[TX1][python+camera][OpenCV3.1.0]: video screen halt

python+camera: video screen halt when I try to open camera in python and opencv3.1.0. My code is:

cam.py code

import numpy as np
import cv2

cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1 ! nvtee ! nvvidconv flip-method=2 ! nvoverlaysink -e ! appsink")


while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    print "loop"

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)



    # Display the resulting frame
    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

Then I got msg when I run it with “python cam.py”:

Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and Mjstreaming
Available Sensor modes :
2592 x 1944 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
2592 x 1458 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
1280 x 720 FR=120.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10

NvCameraSrc: Trying To Set Default Camera Resolution. Selected 1920x1080 FrameRate = 30.000000 ...

There is one frame on the screen, not stream playing…

I tried to remove “nvoverlaysink -e”, but got msg as below:

Available Sensor modes :
2592 x 1944 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
2592 x 1458 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
1280 x 720 FR=120.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10

NvCameraSrc: Trying To Set Default Camera Resolution. Selected 1920x1080 FrameRate = 30.000000 ...


(python:2058): GStreamer-CRITICAL **: gst_element_get_static_pad: assertion 'GST_IS_ELEMENT (element)' failed

(python:2058): GStreamer-CRITICAL **: gst_pad_get_current_caps: assertion 'GST_IS_PAD (pad)' failed

(python:2058): GStreamer-CRITICAL **: gst_caps_get_structure: assertion 'GST_IS_CAPS (caps)' failed

(python:2058): GStreamer-CRITICAL **: gst_structure_get_int: assertion 'structure != NULL' failed

(python:2058): GStreamer-CRITICAL **: gst_structure_get_int: assertion 'structure != NULL' failed

(python:2058): GStreamer-CRITICAL **: gst_structure_get_fraction: assertion 'structure != NULL' failed

Available Sensor modes :
2592 x 1944 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
2592 x 1458 FR=30.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
1280 x 720 FR=120.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10

NvCameraSrc: Trying To Set Default Camera Resolution. Selected 1920x1080 FrameRate = 30.000000 ...

loop

(python:2058): Gtk-WARNING **: cannot open display:

But I got sample codes from other guys looks no problem from them, and most of them are C code…
So want to discuss with community here.

Is it related to gstreamer? I am using JetPack for L4T 2.3.1 64bit. And I just manually installed opencv 3.1.0.

I think I have got the answer…

In fact, I run it though ssh, that means I have to use DISPLAY=:0 before real command, so it works now with below command line:
DISPLAY=:0 sudo python cam.py

This topic could be closed, hope it helps a little for other newbie.

:)

Thanks to everyone!