VideoCapture cannot open camera

Hey, I’m was using a Waveshare IMX219-200 on a Jetson Nano and by calling nvgstcapture-1.0 I was able to see the feed.
But now I want to use it in Python with OpenCV and I cannot manage to get the camera stream. Therefore I was browsing for hours, trying every combination for the VideoCapture and came to the previous topic named “OpenCV Video Capture with GStreamer doesn’t work on ROS-melodic”
Here the lik

I plugged in the code to confirm my source is valid and always get the answer “camera open failed”…

import sys
import cv2

def read_cam():
    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 !  appsink")
    if cap.isOpened():
        cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
        while True:
            ret_val, img = cap.read();
            cv2.imshow('demo',img)
            cv2.waitKey(10)
    else:
     print("camera open failed")

    cv2.destroyAllWindows()


if __name__ == '__main__':
    read_cam()

Error:


[ERROR:0@0.056] global cap.cpp:164 open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.7.0) /io/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): 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 !  appsink in function 'icvExtractPattern'


camera open failed

How can I fix that? What is the problem? The camera works fine but not like that…

You need to specify GSTREAMER backend:

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 ! appsink drop=1", cv2.CAP_GSTREAMER)

Thanks, but apparently GStreamer is not installed / supported on my OpenCV Version.

General configuration for OpenCV 4.7.0 

...


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)

How can I change that? Or is there any other way?

Hi,
You may manually built OpenCV with WITH_GSTREAMER=ON. A user has shared a script:
GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano
Please give it a try.

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