Gstream used by Opencv Freeze (TX2)

I try to read through CSI in TX2 from camera signal throught custom board. I am using Opencv for image post process.

My HW (camera -> custom board -> CSI in TX2)
MY SW (CSI -> Gstream -> Opencv)

My program looks like showing first image and then freeze.

Here are partial my code in Python:

dev = 0
width = 1920
height = 1080
gst_str = ('v4l2src device=/dev/video{} ! ' 
               'video/x-raw, width=3840, height=2160, framerate=30/1, format=UYVY ! ' 
               'nvvidconv ! '
               'video/x-raw(memory:NVMM), width={}, height={}, framerate=30/1, format=I420 ! '
               'nvoverlaysink sync=true !' 
               'videoconvert ! appsink').format(dev, width, height)

cap = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

_, img = # grab the next image frame from camera

Main error message:

(python3:3204): GStreamer-CRITICAL **: 
Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

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_FILE, filename)): 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

In the Terminal, I am able to see the video using the same script:
$ gst-launch-1.0 v4l2src device=/dev/video0 ! 'video/x-raw, width=3840, height=2160, framerate=30/1, format=UYVY' ! nvvidconv ! 'video/x-raw(memory:NVMM), width=1920, height=1080, framerate=30/1, format=I420' ! nvoverlaysink sync=true

What could make the pipeline not launch?

System Spec:
OS: Ubuntu 16.04
Opencv 3.4
Python 3.5
HW: Nvidia TX2


The problem is that you have to decide your pipeline sink.
If you use nvoverlaysink, it is a pure sink and has no output for videoconvert/appsink.

Simply try:

gst_str = ("v4l2src device=/dev/video{} ! video/x-raw, width=3840, height=2160, framerate=30/1, format=UYVY ! nvvidconv ! video/x-raw(memory:NVMM), width={}, height={}, framerate=30/1, format=BGRx ! videoconvert ! appsink").format(dev, width, height)

and if it opens fine, then read frames in the loop.

Thanks for the information. I didn’t suspect ‘nvoverlaysink’.
Unfortunately, I gave up the project related to this issue a month ago, so I won’t have a chance to apply your code line in the Python code.
I will keep your answer and I will apply in the future.