Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -24,11 +24,10 @@ def show_preds_video():
|
|
24 |
count += 1
|
25 |
if count % 2 != 0:
|
26 |
continue
|
27 |
-
|
28 |
frame=cv2.resize(frame,(1020,600))
|
29 |
frame_copy = frame.copy()
|
30 |
-
|
31 |
-
truck_cnt = 0
|
32 |
|
33 |
results=model(frame)
|
34 |
for index, row in results.pandas().xyxy[0].iterrows():
|
@@ -41,28 +40,29 @@ def show_preds_video():
|
|
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 |
-
|
50 |
|
51 |
-
elif ('truck') in d:
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
free_space = total_space -
|
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 |
|
|
|
24 |
count += 1
|
25 |
if count % 2 != 0:
|
26 |
continue
|
27 |
+
|
28 |
frame=cv2.resize(frame,(1020,600))
|
29 |
frame_copy = frame.copy()
|
30 |
+
Vehicle_cnt = 0
|
|
|
31 |
|
32 |
results=model(frame)
|
33 |
for index, row in results.pandas().xyxy[0].iterrows():
|
|
|
40 |
cx=int(x1+x2)//2
|
41 |
cy=int(y1+y2)//2
|
42 |
|
43 |
+
if ('car' or 'truck') in d:
|
44 |
results = cv2.pointPolygonTest(np.array(area, np.int32), ((cx,cy)), False)
|
45 |
if results >0:
|
46 |
cv2.rectangle(frame_copy,(x1,y1),(x2,y2),(0,0,255),2)
|
47 |
cv2.putText(frame_copy,str(d),(x1,y1),cv2.FONT_HERSHEY_PLAIN,2,(255,255,0),2)
|
48 |
+
Vehicle_cnt += 1
|
49 |
|
50 |
+
# elif ('truck') in d:
|
51 |
+
# results = cv2.pointPolygonTest(np.array(area, np.int32), ((cx,cy)), False)
|
52 |
+
# if results >0:
|
53 |
+
# cv2.rectangle(frame_copy,(x1,y1),(x2,y2),(0,0,255),2)
|
54 |
+
# cv2.putText(frame_copy,str(d),(x1,y1),cv2.FONT_HERSHEY_PLAIN,2,(255,0,0),2)
|
55 |
+
# truck_cnt += 1
|
56 |
|
57 |
+
free_space = total_space - Vehicle_cnt
|
58 |
cv2.putText(frame_copy, ("Free space: " + str(free_space)), (50,50) ,cv2.FONT_HERSHEY_PLAIN,2,(0,255,0),2)
|
59 |
+
# 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)
|
60 |
+
cv2.putText(frame_copy, str(str("vehicles: ")+ str(Vehicle_cnt) ), (50,85) ,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 |
|