2

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?

Gian Arauz
  • 423
  • 1
  • 7
  • 14
e.iluf
  • 1,389
  • 5
  • 27
  • 69
  • 1
    what do you mean by "the camera does not work..."? In the python code, you are creating a dummy video source, not a camera video source. – Daniel Sep 21 '22 at 08:02
  • Try changing your pipeline to: **G_STREAM_TO_SCREEN = "videotestsrc num-buffers=50 ! videoconvert ! appsink"** – James Sep 24 '22 at 23:58
  • It could be a permissions issue, does it work if you sudo your python script? – Fraser Sep 26 '22 at 16:21

0 Answers0