AI-Naga commited on
Commit
956ed2f
1 Parent(s): b6b4db2

Upload 6 files

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. Video_1.mp4 +3 -0
  3. app.py +89 -0
  4. image_0.JPG +0 -0
  5. image_1.JPG +0 -0
  6. requirements.txt +8 -0
  7. yolov5l.pt +3 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ Video_1.mp4 filter=lfs diff=lfs merge=lfs -text
Video_1.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cca303b2cea37a6a850ff933cf95e449210cd6101ab7446bb4eaa51124dd42f1
3
+ size 12962985
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import requests
4
+ import os
5
+ import torch
6
+ import numpy as np
7
+ from ultralytics import YOLO
8
+
9
+ model = torch.hub.load('ultralytics/yolov5', 'yolov5l', pretrained=True)
10
+ path = [['image_0.jpg'], ['image_1.jpg']]
11
+ video_path = [['video_test.mp4']]
12
+ # area = [(25,430), (10, 515), (407,485), (750,425), (690,370)]
13
+ area = [(48,430), (18, 515), (407,485), (750,425), (690,370)]
14
+ total_space = 12
15
+ count=0
16
+
17
+ def show_preds_video():
18
+ cap = cv2.VideoCapture('Video_1.mp4')
19
+ count=0
20
+ while(cap.isOpened()):
21
+ ret, frame = cap.read()
22
+ if not ret:
23
+ break
24
+ count += 1
25
+ if count % 2 != 0:
26
+ continue
27
+ # frame = cv2.imread(video_path)
28
+ frame=cv2.resize(frame,(1020,600))
29
+ frame_copy = frame.copy()
30
+ car_cnt = 0
31
+ truck_cnt = 0
32
+
33
+ results=model(frame)
34
+ for index, row in results.pandas().xyxy[0].iterrows():
35
+ x1 = int(row['xmin'])
36
+ y1 = int(row['ymin'])
37
+ x2 = int(row['xmax'])
38
+ y2 = int(row['ymax'])
39
+ d=(row['name'])
40
+
41
+ cx=int(x1+x2)//2
42
+ cy=int(y1+y2)//2
43
+
44
+ if ('car') in d:
45
+ results = cv2.pointPolygonTest(np.array(area, np.int32), ((cx,cy)), False)
46
+ if results >0:
47
+ cv2.rectangle(frame_copy,(x1,y1),(x2,y2),(0,0,255),2)
48
+ cv2.putText(frame_copy,str(d),(x1,y1),cv2.FONT_HERSHEY_PLAIN,2,(255,255,0),2)
49
+ car_cnt += 1
50
+
51
+ elif ('truck') in d:
52
+ results = cv2.pointPolygonTest(np.array(area, np.int32), ((cx,cy)), False)
53
+ if results >0:
54
+ cv2.rectangle(frame_copy,(x1,y1),(x2,y2),(0,0,255),2)
55
+ cv2.putText(frame_copy,str(d),(x1,y1),cv2.FONT_HERSHEY_PLAIN,2,(255,0,0),2)
56
+ truck_cnt += 1
57
+
58
+ free_space = total_space - (car_cnt + truck_cnt)
59
+ cv2.putText(frame_copy, ("Free space: " + str(free_space)), (50,50) ,cv2.FONT_HERSHEY_PLAIN,2,(0,255,0),2)
60
+ cv2.putText(frame_copy, str(str(" car: ")+ str(car_cnt) + str(" truck: ") +str(truck_cnt)), (50,75) ,cv2.FONT_HERSHEY_PLAIN,2,(0,255,0),2)
61
+
62
+ cv2.polylines(frame_copy, [np.array(area, np.int32)], True, (0,255,0), 2)
63
+
64
+ fps = cap.get(cv2.CAP_PROP_FPS)
65
+ cv2.putText(frame_copy,str("fps: ") + str(np.round(fps,0)),(50,100),cv2.FONT_HERSHEY_PLAIN,2,(0,255,0),2)
66
+
67
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
68
+
69
+
70
+ inputs_video = [
71
+ #gr.components.Video(type="filepath", label="Input Video"),
72
+
73
+ ]
74
+ outputs_video = [
75
+ gr.components.Image(type="numpy", label="Output Image"),
76
+ ]
77
+ interface_video = gr.Interface(
78
+ fn=show_preds_video,
79
+ inputs=inputs_video,
80
+ outputs=outputs_video,
81
+ title="Parking space counter",
82
+ # examples=video_path,
83
+ cache_examples=False,
84
+ )
85
+
86
+ gr.TabbedInterface(
87
+ [interface_video],
88
+ tab_names=['Video inference']
89
+ ).queue().launch()
image_0.JPG ADDED
image_1.JPG ADDED
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ gradio==3.4.0
3
+ opencv-python
4
+ numpy<1.24
5
+ ultralytics
6
+ yolov5
7
+
8
+
yolov5l.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f603b7354c25454d1270663a14d8ddc1eea98e5eebc1d84ce0c6e3150fa155f
3
+ size 93622629