I’m trying to read from the onboard camera with opencv and even after following many other solutions online, can not get it to work. When I try with code like:
This means you are trying to display a void frame.
Main cause may be a typo in your pipeline: nvarguscamerasrc, so the pipeline failed to start.
You would test if the videoCapture is opened before reading from it (cam.isOpened()) and also check return code from cap.read() before using frame.
Sorry for the typo in my original post, but I double checked the code and I do have nvarguscamerasrc (don’t know how that happened).
When I print the value of cam.read() I get (False, none).
I’ve tried a number of variations on the input for cv2.VideoCapture and nothing has worked, so I’m unable to tell what is wrong other than the fact that the camera is not starting. Also, I tried that code I linked and it didn’t work either, which seems strange.
Sorry I missed that from your code, but output format is NV12 for nvarguscamerasrc, it was I420 in older releases with nvcamerasrc.
Try:
import cv2
cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! queue ! appsink drop=1", cv2.CAP_GSTREAMER)
if not cap.isOpened():
print('Failed to open camera')
exit
cv2.namedWindow('Demo', cv2.WINDOW_AUTOSIZE)
# Run for 300 frames
for i in range(300):
ret_val, img = cap.read();
if not ret_val:
break
cv2.imshow('Demo', img);
cv2.waitKey(1)
cv2.destroyAllWindows()
cap.release()
This must be the problem: GStreamer is set to no.
I don’t remember building OpenCV from source on my Jetson, will that now be necessary? Do you have any recommendations for the TX2 specifically? I’ve run into a lot of issues building other applications from source on the Jetson, so any advice here would be appreciated.