Spaces:
Sleeping
Sleeping
Update Yolov5_Deepsort/demo.py
Browse files- Yolov5_Deepsort/demo.py +46 -43
Yolov5_Deepsort/demo.py
CHANGED
|
@@ -62,49 +62,52 @@ def main():
|
|
| 62 |
cv2.destroyAllWindows()
|
| 63 |
|
| 64 |
def app_main(video):
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
if __name__ == '__main__':
|
| 110 |
|
|
|
|
| 62 |
cv2.destroyAllWindows()
|
| 63 |
|
| 64 |
def app_main(video):
|
| 65 |
+
try:
|
| 66 |
+
name = 'demo'
|
| 67 |
+
det = Detector()
|
| 68 |
+
cap = cv2.VideoCapture(video)
|
| 69 |
+
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
| 70 |
+
print('fps:', fps)
|
| 71 |
+
t = int(1000 / fps)
|
| 72 |
+
frame_count = 0
|
| 73 |
+
total_time = 0
|
| 74 |
+
|
| 75 |
+
videoWriter = None
|
| 76 |
+
output_filename = 'result.mp4'
|
| 77 |
+
|
| 78 |
+
while True:
|
| 79 |
+
start_time = time.time()
|
| 80 |
+
|
| 81 |
+
ret, im = cap.read()
|
| 82 |
+
if not ret:
|
| 83 |
+
break
|
| 84 |
+
|
| 85 |
+
result = det.feedCap(im)
|
| 86 |
+
result = result['frame']
|
| 87 |
+
result = imutils.resize(result, height=500)
|
| 88 |
+
|
| 89 |
+
if videoWriter is None:
|
| 90 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 91 |
+
videoWriter = cv2.VideoWriter(
|
| 92 |
+
output_filename, fourcc, fps, (result.shape[1], result.shape[0]))
|
| 93 |
+
|
| 94 |
+
videoWriter.write(result)
|
| 95 |
+
|
| 96 |
+
end_time = time.time()
|
| 97 |
+
total_time += (end_time - start_time)
|
| 98 |
+
frame_count += 1
|
| 99 |
+
|
| 100 |
+
if frame_count > 0:
|
| 101 |
+
processing_fps = frame_count / total_time
|
| 102 |
+
print('Processing fps:', processing_fps)
|
| 103 |
+
|
| 104 |
+
cap.release()
|
| 105 |
+
videoWriter.release()
|
| 106 |
+
|
| 107 |
+
return output_filename
|
| 108 |
+
except Exception as e:
|
| 109 |
+
print(f"Error in app_main: {e}")
|
| 110 |
+
return None
|
| 111 |
|
| 112 |
if __name__ == '__main__':
|
| 113 |
|