I have tried many attempts to run the cameras connected to my jetson nano. When I run this command:
gst-launch-1.0 -v nvarguscamerasrc ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1' ! autovideosink
The camera works but when I try to perform a simple camera read in python with this code
import sys
import cv2
def read_cam():
G_STREAM_TO_SCREEN = "videotestsrc num-buffers=50 ! videoconvert ! appsink"
cap = cv2.VideoCapture(G_STREAM_TO_SCREEN, cv2.CAP_GSTREAMER)
if cap.isOpened():
cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
while True:
ret_val, img = cap.read()
cv2.imshow('demo',img)
cv2.waitKey(1)
else:
print ("Unable to use pipline")
cv2.destroyAllWindows()
if __name__ == '__main__':
read_cam()
the camera does not work in the code above and it returns "Unable to use pipline".
What I am doing wrong and how can I access the camera feed in python?