Gstramer: No with using Python but terminal ok

Hello,

The CSI camera works in the terminal, but it doesn’t work with Python in Visual Studio. I’m using a Jetson Orin Nano. The camera works when I run the following command in the terminal:

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1' ! nvvidconv ! nvegltransform ! nveglglessink -e

However, the camera does not work in the following Python script:

import cv2

cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink")

while True:
    ret, frame = cap.read()
    if not ret:
        print("Unable to capture camera image")
        break

    cv2.imshow("CSI Camera", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

I receive the following output when I run the script:

onur@ubuntu:~/Desktop/Project$ /bin/python /home/onur/Desktop/Project/simple_camera.py
nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)960, height=(int)540, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
Error: Unable to open camera

Upon researching, I was advised to run the following code:

import cv2
print(cv2.getBuildInformation())

In the output, I saw:

Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES
      avcodec:                   YES (59.37.100)
      avformat:                  YES (59.27.100)
      avutil:                   YES (57.28.100)
      swscale:                  YES (6.7.100)
      avresample:                NO
    GStreamer:                   NO
    v4l/v4l2:                    YES (linux/videodev2.h)

It seems that the GStreamer: NO line indicates a problem. How can I solve this?

Hello @onurrcifcii,

Can you please try running the following pipe on a console?

gst-launch-1.0 nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! fakesink

Please let us know how it goes.

regards,
Andrew
Embedded Software Engineer at ProventusNova

Hi @proventusnova
I reinstalled Opencv so that “gstreamer” would be ok and gstreamer was ok. I tried the code at that moment and the code worked but I closed and opened it and now it doesn’t work again. My previous outputs are like this:

onur@ubuntu:~$ gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1' ! nvvidconv ! nvegltransform ! nveglglessink -e
Setting pipeline to PAUSED ...

Using winsys: x11 
Pipeline is live and does not need PREROLL ...
Got context from element 'eglglessink0': gst.egl.EGLDisplay=context, display=(GstEGLDisplay)NULL;
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:794 No cameras available
Redistribute latency...
WARNING: from element /GstPipeline:pipeline0/GstEglGlesSink:eglglessink0: Pipeline construction is invalid, please add queues.
Additional debug info:
../libs/gst/base/gstbasesink.c(1249): gst_base_sink_query_latency (): /GstPipeline:pipeline0/GstEglGlesSink:eglglessink0:
Not enough buffering available for  the processing deadline of 0:00:00.015000000, add enough queues to buffer  0:00:00.015000000 additional data. Shortening processing latency to 0:00:00.000000000.
WARNING: from element /GstPipeline:pipeline0/GstEglGlesSink:eglglessink0: Pipeline construction is invalid, please add queues.
Additional debug info:
../libs/gst/base/gstbasesink.c(1249): gst_base_sink_query_latency (): /GstPipeline:pipeline0/GstEglGlesSink:eglglessink0:
Not enough buffering available for  the processing deadline of 0:00:00.015000000, add enough queues to buffer  0:00:00.015000000 additional data. Shortening processing latency to 0:00:00.000000000.
Got EOS from element "pipeline0".
EOS received - stopping pipeline...
Execution ended after 0:00:00.049180177
Setting pipeline to NULL ...
Freeing pipeline ...

And the camera doesn’t work here anymore either.

Other try:

import cv2

cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink")

while True:
    ret, frame = cap.read()
    if not ret:
        print("Unable to capture camera image")
        break

    cv2.imshow("CSI Camera", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

output:

onur@ubuntu:~/Desktop/Project$ /bin/python "/home/onur/Desktop/Project/deneme111 copy.py"
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:794 No cameras available
[ WARN:0@0.200] global cap_gstreamer.cpp:1777 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Unable to capture camera image

Your suggested code and output:

onur@ubuntu:~$ gst-launch-1.0 nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! fakesink
bash: syntax error near unexpected token `('
onur@ubuntu:~$ gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1' ! nvvidconv ! 'video/x-raw, format=BGRx' ! videoconvert ! 'video/x-raw, format=BGR' ! fakesink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:794 No cameras available
Redistribute latency...
Got EOS from element "pipeline0".
Execution ended after 0:00:00.004239403
Setting pipeline to NULL ...
Freeing pipeline ...

Can you help me please.

Hello @onurrcifcii,

The No cameras available error message suggests that there might have been a problem with argus that now causes the cameras not to be detected.

You can check if the cameras are still available with:

ls /dev/video*

If you can see the video devices, then you might need to restart the board to see if the cameras come back up again.

You can also try restarting the Argus Daemon:

sudo service nvargus-daemon restart

Please let me know how it goes.

regards,
Andrew
Embedded Software Engineer at ProventusNova

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.