在Jetson Nano上使用python opencv加载相机的问题

时间:2020-10-21 07:50:15

标签: python opencv nvidia-jetson-nano

我有一个连接到jetson nano的树莓派相机v2。我可以通过运行命令 gst-launch-1.0 nvarguscamerasrc sensor_mode = 0来加载摄像机! '视频/ x-原​​始(内存:NVMM),宽度= 3820,高度= 2464,帧率= 21/1,格式= NV12'! nvvidconv flip-method = 0! 'video / x-raw,width = 960,height = 616'! nvvidconv! nvegltransform! nveglglessink -e 成功。

现在,我正在尝试在python中构建一个模块,该模块将加载相机并将图像写入磁盘。但是我收到错误 [WARN:0]全局/home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp(933)打开OpenCV | GStreamer警告:无法查询视频位置:status = 0,value = -1,duration = -1

我构建的代码在具有USB摄像头的Windows机器上可以正常工作。

有人可以帮我解决这个问题吗?

python版本-3.6.9

opencv版本-4.1.1

代码-

import cv2
import PIL
from PIL import Image

camera_port = 0
ramp_frames = 30

GSTREAMER_PIPELINE = 'nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1920, height=1080, format=(string)NV12, framerate=21/1 ! nvvidconv flip-method=0 ! video/x-raw, width=960, height=616, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink'

camera = cv2.VideoCapture(GSTREAMER_PIPELINE, cv2.CAP_GSTREAMER)

def get_image():
    retval, im = camera.read()
    return im
for i in range(ramp_frames):
    temp = camera.read()

camera_capture = get_image()
im_rgb = cv2.cvtColor(cam`enter code here`era_capture, cv2.COLOR_BGR2RGB)
Image.fromarray(im_rgb).save('webcamfeed.jpg')
del(camera)

0 个答案:

没有答案