Spaces:
Sleeping
Sleeping
File size: 1,514 Bytes
eff01bb 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 |
from .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()
if __name__ == '__main__':
main() |