Segmentation fault accessing nvarguscamerasrc

So, I am trying to build an openCV app, to take advantage of the cuda functionality on a TX2/TX2i. I am currently running JetPack 4.5, as I had everything setup on this version already before 4.6 came out. This is the python code that I got, and that prompts a segmentation fault. I am positive that it is built with gstreamer and cuda.

Any ideas?

#!/usr/bin/env python3
import cv2
import numpy as np
import sys

# print(cv2.getBuildInformation())

test_camera = ("nvarguscamerasrc sensor-id=0 sensor-mode=0 ! video/x-raw(memory:NVMM),framerate=1/1,format=(string)NV12,width=5328,height=4608 ! nvvidconv ! video/x-raw,framerate=1/1,format=NV12,width=133
2,height=1152 ! appsink")

# first_camera = ("nvarguscamerasrc sensor-id=0 sensor-mode=0 ! video/x-raw(memory:NVMM),width=2048,height=2048,framerate=1/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! appsink")
# second_camera = ("nvarguscamerasrc sensor-id=1 sensor-mode=0 ! video/x-raw(memory:NVMM),width=2048,height=2048,framerate=1/1")

cap = cv2.VideoCapture(test_camera, cv2.CAP_GSTREAMER)
if not cap.isOpened():
        print ('Failed to open camera')

        ret, img = # grab the next image frame from camera
        #cv2.cvtColor(img, cv2.COLOR_YUV2RGB_NV12)
        #cv2.cvtColor(img, cv2.COLOR_YCrCb2RGB)
        cv2.imshow('frame', img)
        key = cv2.waitKey(10)

Hi @Mircea_Zisu

test_camera is a list, I suppose it should be a string.
This code doesn’t use cuda, so seg fault happens on gstreamer or opencv.
Can you paste the exact error message, and point the Python code line where it happens?

Hello Alejandro,
In all examples that I had seen, it was a list, and not a string. And even if I remove the list part, nothing changes.

Here is what shows up.

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 0
Output Stream W = 5328 H = 4608
seconds to Run = 0
Frame Rate = 15.000000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
NVMAP_IOC_READ failed: Interrupted system call
NVMAP_IOC_READ: Offset 1835008 SrcStride 1536 pDst 0x7f3af42aa0 DstStride 1336 Count 576
[ WARN:0] global /home/mircea/JEP/script/workspace/opencv-4.5.0/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
NVMAP_IOC_READ failed: Interrupted system call
NVMAP_IOC_READ: Offset 1835008 SrcStride 1536 pDst 0x7f383a7aa0 DstStride 1336 Count 576
[1] 16121 segmentation fault (core dumped) ./

Also, I was mainly giving some context to the reason why I am doing this, as I am running into so many more issues all of the time, while trying to build this application.

It is wise of you to test with this toy code.

The error comes from NVidia, NVMAP_IOC_READ when trying to get a frame.

OpenCV asks GStreamer to open the stream, it asks NVidia, and NVidia fails. It doesn’t matter if it is GStreamer or ffmpeg.

While it is not OpenCV related error, I saw many users reporting this at NVidia with many contextual answers like update your NVidia software, that special feature is not supported, and so on.

Please google NVMAP_IOC_READ.

And yes, develop on NVidia hardware is a pain, but sometimes it worth it.

an expression like ("foo") is not a list, nor a tuple. it’s simply a string with parentheses around it

("foo", ) would be a 1-tuple

VideoCapture wants a string, so the first expression is okay, but the parentheses are pointless

if not ret: break

1 Like

Segmentation fault still occurs. I had written a print statement as well, and the text does not appear.

After putting a few more, it seems that it gets to the while True just fine, and only in there something breaks. It seems to be consistent though, that the while True loop runs three times, and then causes a segmentation fault.

The only way I have been able to stop the segmentation fault from happening is by removing format=NV12 from right before the appsink, but then I am not sure what colour format it is.

test_camera = ("nvarguscamerasrc sensor-id=0 sensor-mode=0 ! video/x-raw(memory:NVMM),framerate=1/1,format=NV12,width=5328,height=4608 ! nvvidconv ! video/x-raw,framerate=1/1,width=1332,height=1152,format=NV12 ! appsink")
1 Like