【问题标题】:cv2.VideoWriter doesn't work well on Jetson Nanocv2.VideoWriter 在 Jetson Nano 上无法正常工作
【发布时间】:2019-12-23 02:44:10
【问题描述】:

我在 Jetson Nano 上使用 OpenCV v.4.1.0 通过 RPi 摄像头捕捉视频,而模块 cv2.VideoWriter 无法很好地保存视频。文件为空。

我已经在 RPi 3B+ 上证明了 cv2.VideoWriter 并且效果很好。

import numpy as np
import cv2

capture_height = 720
capture_width = 1280
frame_rate = 21
display_width = 860
display_height = 640
flip_method = 0

gstr = ('nvarguscamerasrc ! video/x-raw(memory:NVMM),'
        'width=%s, height=%s,'
        'framerate= %s'
        'format=NV12 ! nvvidconv flip-method= %s ! video/x-raw,'   
        'width=%s, height=%s,'
        'format=BGRx ! videoconvert ! appsink'
        % (capture_width, capture_height, frame_rate, flip_method, 
        display_width, display_height))

filename = 'video.avi'
fourcc = cv2.VideoWriter_fourcc(*'XVID')

cap = cv2.VideoCapture(gstr, cv2.CAP_GSTREAMER)
out = cv2.VideoWriter(filename, fourcc, float(frame_rate), 
                     (capture_width,capture_height),True)

while True:
    ret, img = cap.read()
    out.write(img)
    cv2.imshow('img',img)
    if cv2.waitKey(1) & 0xff == ord('q'):
        break

cap.release()
out.release()
cv2.destroyAllWindows()

此代码应显示来自 RPi 相机的图像,并以 .avi 格式保存视频。

【问题讨论】:

  • 您可以尝试不同的编解码器吗?
  • 我已经这样做了,但仍然无法正常工作:(
  • 它还可以识别编解码器:>>> cv2.VideoWriter_fourcc(*'XVID')1145656920

标签: python opencv nvidia-jetson nvidia-jetson-nano


【解决方案1】:

解决方法是输入:

out = cv2.VideoWriter(filename, fourcc, float(frame_rate),
                      (display_width, display_height), True)

【讨论】:

    猜你喜欢
    • 2022-12-13
    • 2018-07-06
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    相关资源
    最近更新 更多