Seg Fault OpenCV .release()

I’m able to grab a single image from a CSI camera and display it in a cv2 window but my program keeps crashing when I try to release the VideoCapture object. This is a problem because I still need to be able to run code after I close a camera.

Here’s my code:

import cv2

cap = cv2.VideoCapture("nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv ! video/x-raw,format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")

_, frame =

cv2.imshow("Frame", frame)

while True:
    if cv2.waitKey(1) == 27:


print("This print doesn't run")

I built opencv using this tutorial and I’m running the program just through the system terminal. It seems weird to me that this program crashes as it’s fairly simple. Could this be an issue with my build or my hardware? I’ve tried using the Visual Studio Code debugger and it hasn’t provided any additional info. Thanks in advance!

release seg fault

I got the same problem too, refer to my post about this, hopefully it helps.

Please share which release you use:

head -1 /etc/nv_tegra_release

It looks to be a known issue in previous version but should have been fixed in r32.5.x.

Thank you this worked!

1 Like

I’m currently on R32.5.1 but cap’s answer solved my problem. Thank you for your help!

Command output in case it’s necessary

# R32 (release), REVISION: 5.1, GCID: 27362550, BOARD: t186ref, EABI: aarch64, DATE: Wed May 19 18:06:00 UTC 2021