【发布时间】:2020-07-30 16:26:38
【问题描述】:
我有一个涉及对象检测的项目,它在对象周围创建了边界框,我想保存视频。 我尝试过的:
out = cv2.VideoWriter('/content/gdrive/My Drive/cam_output_final.avi',cv2.VideoWriter_fourcc('m','p','4','v'), 30, (288, 1024))
fr_num = 0
while True:
ret1, frame1 = shortCap.read()
ret2, frame2 = longCap.read()
r1, image1 = make_detections(frame1, mRcnn)
frame1_final, pep_cnt1 = visualize_results(image1, r1)
r2, image2 = make_detections(frame2, mRcnn)
frame2_final, pep_cnt2 = visualize_results(image2, r2)
cv2.putText(frame1_final, 'Number of people: {}'.format(str(pep_cnt1)),
(50, 260), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 1)
cv2.putText(frame2_final, 'Number of people: {}'.format(str(pep_cnt2)),
(50, 260), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 1)
print(frame1_final.shape) # shape = (288, 512, 3)
print(frame2_final.shape) # shape = (288, 512, 3)
both = np.concatenate((frame1_final, frame2_final), axis=1)
print(both.shape) # shape = (288, 1024, 3)
print(fr_num)
out.write(both)
fr_num += 1
if fr_num > 5:
break
cap1.release()
cap2.release()
cv2.destroyAllWindows()
我已经尝试了所有方法,但根本没有节省! 每次保存 cam_output.avi 文件的大小为 5.55K!它不起作用!
【问题讨论】:
-
确保您的应用程序可以访问 opencv_ffmpeg dll 文件。通过编写“MJPG”视频来测试它。如果要保存 mp4 文件,则必须为文件名选择 .mp4 扩展名。
-
@Micka 不工作!
-
frame.shape显示尺寸(height, width)-(288, 1024)- 但VideoWriter需要尺寸(width, height)- 这意味着(1024, 288)