【问题标题】:cannot write video in opencv python无法在opencv python中写入视频
【发布时间】: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)

标签: python opencv opencv3.0


【解决方案1】:

frame.shape 显示大小 (height, width) - 表示 (288, 1024) - 但 VideoWriter 需要大小 (width, height) - 表示 (1024, 288)

out = cv2.VideoWriter(..., (1024, 288))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2016-06-27
    • 2017-10-19
    • 1970-01-01
    • 2017-07-28
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多