OpenCV Deallocation Segmentation Fault

Hello Everyone,

This is my first post here!

I’m using OpenCV to capture images from Raspberry Pi V2 camera on the jetson nano 2GB.

The following explanation of code is written in c++.

I’m using gstreamer/opencv for initialization of the camera interface and I convert the image format from NV12 to BGRx, then the application converts BGRx to RGB so that detectnet can make detections on the image.

I’m using openCV for the input stream, detectnet for the detections, and jetson-utils.VideoOutput.render() to output the video onto the screen so I can see the detections working.

When I run the camera without object detection and image conversion from BGRx to RGB, I don’t get a segmentation fault. Deallocation is successful.

however as soon as I add the object detection and image conversion code, I get a segmentation fault on CV.VideoCapture.release().

Can anyone provide any idea on what is the possible reason? I would prefer if I don’t have to go into openCV and start modifying the source code.

Also if code is needed I can provide it.

I think I’m using opencv4 and jetpack 4.5.

Thank you!


I have been able to get good FPS for detection. What I did was close Visual Studio Code and just run my project from the terminal.

However I’m still getting the deallocation segmentation fault upon exit from the program.

I am thinking this is a resource issue.

Please check if you can apply the object detection and image conversion to
OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL

And see if the issue still happens.

1 Like

Also try adding drop=1 into appsink properties in opencv videoCapture pipeline:

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 ! video/x-raw, format=BGR ! appsink drop=1")
1 Like

@Honey_Patouceul ,
This works, thank you!

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