Spaces:
Running
Running
File size: 2,830 Bytes
8915a64 d1568e7 ab74696 c9090c9 ab74696 d1568e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 110 111 112 113 114 |
from Yolov5_Deepsort.AIDetector_pytorch import Detector
import imutils
import rich
import cv2
import time
def main():
name = 'demo'
det = Detector()
cap = cv2.VideoCapture('mot.mp4')
fps = int(cap.get(5))
print('fps:', fps)
t = int(1000/fps)
frame_count = 0
total_time = 0
videoWriter = None
while True:
start_time = time.time()
# try:
_, im = cap.read()
if im is None:
break
#rich.print("im:",im)
result = det.feedCap(im)
#rich.print(result)
result = result['frame']
result = imutils.resize(result, height=500)
if videoWriter is None:
fourcc = cv2.VideoWriter_fourcc(
'm', 'p', '4', 'v') # opencv3.0
videoWriter = cv2.VideoWriter(
'result.mp4', fourcc, fps, (result.shape[1], result.shape[0]))
videoWriter.write(result)
cv2.imshow(name, result)
cv2.waitKey(t)
end_time = time.time()
total_time += (end_time - start_time)
frame_count +=1
if frame_count > 0:
processing_fps = frame_count / total_time
rich.print('Processing fps:', processing_fps)
if cv2.getWindowProperty(name, cv2.WND_PROP_AUTOSIZE) < 1:
# 点x退出
break
# except Exception as e:
# print(e)
# break
cap.release()
videoWriter.release()
cv2.destroyAllWindows()
def app_main(video):
try:
name = 'demo'
det = Detector()
cap = cv2.VideoCapture(video)
fps = int(cap.get(cv2.CAP_PROP_FPS))
print('fps:', fps)
t = int(1000 / fps)
frame_count = 0
total_time = 0
videoWriter = None
output_filename = 'result.mp4'
while True:
start_time = time.time()
ret, im = cap.read()
if not ret:
break
result = det.feedCap(im)
result = result['frame']
result = imutils.resize(result, height=500)
if videoWriter is None:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
videoWriter = cv2.VideoWriter(
output_filename, fourcc, fps, (result.shape[1], result.shape[0]))
videoWriter.write(result)
end_time = time.time()
total_time += (end_time - start_time)
frame_count += 1
if frame_count > 0:
processing_fps = frame_count / total_time
print('Processing fps:', processing_fps)
cap.release()
videoWriter.release()
return output_filename
except Exception as e:
print(f"Error in app_main: {e}")
return None
if __name__ == '__main__':
main() |