Cannot Open the Camera on Nvidia Jetson Nano and Raspberry V2.1 Camera via OpenCV and Phyton Code

Hi, I am using Nvidia Jetson Nano and Raspberry Pi V2.1 Camera for color detection via Python and OpenCV. However, the codes that worked on my computer do not work on Jetson Nano and I keep getting errors. The code is so simple, I just wanted to open the camera and get the real time view.

This is my code:

import cv2
print(cv2.version)
dispW=320
dispH=240
flip=2
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)

while True:
ret, frame=cam.read()
cv2.imshow(“camera”,frame)
if cv2.waitKey(1) ==ord(“q”):
break
cam.release()
cv2.destroyAllWindows()

And this is the error:

3.2.0

OpenCV Error: Assertion failed (size.width>0 &&

size.height>0) in imshow, file /build/opencv-XDqSFW/opencv 3.2.0+dfsg/modules/highgui/src/window.cpp, line 304

Traceback (most recent call last): File “camera.py”, line 12, in

cv2.imshow(“camera”,frame)

cv2.error: /build/opencv-XDqSFW/opencv

3.2.0+dfsg/modules/highgui/src/window.cpp:304: error: (-215)

size.width>0&& size.height>0 in function imshow

You try to imshow an empty Mat. Now, you need to figure out how to check that the read() succeeded before doing anything with the frame