微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Jetson Nano 运行测试相机代码错误

如何解决Jetson Nano 运行测试相机代码错误

设备:Jetson Nano

我的经验水平:非常低

我的学习意愿:非常高

代码

import cv2

print(cv2.__version__)

dispW=640

dispH=480
flip=2
#Uncomment These next Two Line for Pi Camera
camSet='nvarguscamerasrc !  video/x-raw(memory:NVMM),width=3264,height=2464,format=NV12,framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw,width='+str(dispW)+',height='+str(dispH)+',format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink'
cam= cv2.VideoCapture(camSet)

#Or,if you have a WEB cam,uncomment the next line
#(If it does not work,try setting to '1' instead of '0')
#cam=cv2.VideoCapture(0)
while True:
ret,frame = cam.read()
cv2.imshow('nanoCam',frame)
if cv2.waitKey(1)==ord('q'):
    break
cam.release()
cv2.destroyAllWindows()

错误

python3 
Test2.py
4.5.1

[ERROR:0] global /tmp/pip-req-build-zuuo394f/opencv/modules/videoio/src/cap.cpp (140) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.1) /tmp/pip-req-build-zuuo394f/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): nvarguscamerasrc !  video/x-raw(memory:NVMM),framerate=21/1 ! nvvidconv flip-method=2 ! video/x-raw,width=640,height=480,format=BGR ! appsink in function 'icvExtractPattern'


Traceback (most recent call last):
File "Test2.py",line 15,in <module>
cv2.imshow('nanoCam',frame)
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-zuuo394f/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion Failed) size.width>0 && size.height>0 in function 'imshow'

我正在关注的教程: https://www.youtube.com/watch?v=LXuFYRewBRY 摄像头模块: “IMX219-77相机”我认为功能与pi相机相同

解决方法

您正在尝试从 GStreamer 输入中读取数据,您需要告诉 cv2。 试试

cam = cv2.VideoCapture(camSet,cv2.CAP_GSTREAMER)

还要确保在 cv2 安装中启用了 GStreamer 支持(据我所知,在某些 Jetson 映像上默认情况下未安装它)。您可以查看

import cv2
print(cv2.getBuildInformation())

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。