GStreamer: Error when accessing onboard camera

Hey folk,

when i try to access the onboard camera with a script using opencv (not tegra version) i get the following error:

VIDEOIO ERROR: V4L: device : Unable to query number of channels
GStreamer: Error opening bin: empty pipeline not allowed

Does anyone please has a solution for me to fix that issue?

Thank you very much, tobi

So for example, if i excecute the following script to show the onboard camera image using opencv:

import sys
import cv2

def read_cam():
    cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! 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()

I get the following error message:

Opening in O_NONBLOCKING MODE 
VIDEOIO ERROR: libv4l unable convert to requested pixfmt
Opening in BLOCKING MODE 
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT

OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /home/nvidia/src/opencv-3.4.0/modules/videoio/src/cap_gstreamer.cpp, line 890
VIDEOIO(cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, reinterpret_cast<char *>(index))): raised OpenCV exception:

/home/nvidia/src/opencv-3.4.0/modules/videoio/src/cap_gstreamer.cpp:890: error: (-2) GStreamer: unable to start pipeline
 in function cvCaptureFromCAM_GStreamer

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/nvidia/src/opencv-3.4.0/modules/imgproc/src/color.cpp, line 11111
Traceback (most recent call last):
  File "opencv_cam_tester.py", line 11, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: /home/nvidia/src/opencv-3.4.0/modules/imgproc/src/color.cpp:11111: error: (-215) scn == 3 || scn == 4 in function cvtColor

I am not very familar with GStreamer and V4L2 so it would be very helpful to get some help to fix this. Thank you very much.

Hi,
We have deprecated nvcamerasrc plugin in r32 releases. Do you use r28 releases? You may check if you can run

$ gst-inspect-1.0 nvcamerasrc
$ gst-launch-1.0 nvcamerasrc ! nvoverlaysink

The following command shows the release version:

$ head -1 /etc/nv_tegra_release

hey @DaneLLL, if i exucute the first command, i get the following error:

No such element or plugin 'nvcamerasrc'

if i than execute the second command i get the following error:

WARNING: erroneous pipeline: no element "nvcamerasrc"

Executing the third command runs without error and prints:

# R32 (release), REVISION: 2.0, GCID: 15966166, BOARD: t186ref, EABI: aarch64, DATE: Wed Jul 17 00:26:04 UTC 2019

Do you have a idea to get my issue fixed?

thank you.

Hi,
Please use nvarguscamerasrc.

dear @DaneLLL can you please give me a hint on how to install and use this? i am not very familar with camera pipeline software like this.

thank you very much

iam sorry, this was a little bit stupid written, what i meant is, could you give me a hint for a nvarguscamerasrc pipeline stream to use

I am using the following pipeline stream but it causes errors:

'nvarguscamerasrc ! '
    'video/x-raw(memory:NVMM), '
    'width=(int)%d, height=(int)%d, '
    'format=(string)NV12, framerate=(fraction)%d/1 ! '
    'nvvidconv flip-method=%d ! '
    'video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! '
    'videoconvert ! '
    'video/x-raw, format=(string)BGR ! appsink'

If i run it inside opencvs VideoCapture it gives error:

Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:532 Failed to create CaptureSession

and

Unable to query number of channels

Hi,
we have verified below steps:
https://devtalk.nvidia.com/default/topic/1057460/jetson-tx2/custom-built-opencv-3-4-0-following-nvidia-advice-not-working/post/5363355/#5363355
Please check if you can run the C code, and then adapt the pipeline to your python code.