Jetson Nano using a simple camera to capture code error

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
print('cap.isOpened')
if cap.isOpened():
    print ('cap is opened')
    while(True):
        re,img=cap.read()
        cv2.imshow("video output", img)
        k = cv2.waitKey(10)&0xFF
        if k==27:
            break
cap.release()
cv2.destroyAllWindows()

system print error

(process:26631): GStreamer-CRITICAL **: 13:02:27.677: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Opening in O_NONBLOCKING MODE

We tried DISPLAY=:0 and it still printed the messages.

Hi,

EGL error should happen in “cv2.imshow(“video output”, img)” but not camera.

Are you using ubuntu desktop or the console mode? Are you able to see the display info through xrandr command?

Hi,
I use Jetson Nano Developer Kit

What message do you want to see?

(process:26631): GStreamer-CRITICAL **: 13:02:27.677: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Opening in O_NONBLOCKING MODE

Hi,
It looks like the OpenCV code is running a gstreamer pipeline. Please share the pipeline for reference. Also do you install the system via sdkmanger(Jetpack4.2.1)?

Hi,
I did install it sdkmanger(Jetpack4.2.1)system

Do you also install the opencv through sdkmanager? The opencv from sdkmanager does not support gstreamer.

YES,install the opencv-3.4.6 version.
what ?

Ok, so you are not installing the opencv from sdkmanager.

Please open up a terminal and use

export DISPLAY=:0 
xrandr

Are you able to see the result?

I see the result Invalid MIT-MAGIC-COOKIE-1 keyCan’t open display :0

ChenHoung,

Are you sure you provide the full code in #1?

You are not using any gstreamer pipeline in your code but the error comes from gstreamer.

(process:26631): GStreamer-CRITICAL **: 13:02:27.677: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed

Do you connect a hdmi? Does it light up?
What kind of camera are you using?

Provide the correct code
Really connect HDMI
Using the Camera: Azure Kinect DK

ChenHoung,

  1. If you remove the line " cv2.imshow(“video output”, img)", will you hit any error? It is just debug step.

  2. How about export DISPLAY=:1 and run xrandr? Would you see the display info?

  1. no
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384
HDMI-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 600mm x 340mm
   1920x1080     60.00*+  59.99    59.95    50.00  
   1680x1050     59.96  
   1600x1200     60.01  
   1440x900      59.89  
   1366x768      59.79  
   1280x1024     75.03    60.00  
   1280x960      60.00  
   1280x720      60.00    59.94    50.00  
   1152x864      75.00  
   1024x768      75.03    70.07    60.01  
   832x624       75.05  
   800x600       75.00    72.19    60.32    56.25  
   720x576       50.00  
   720x480       59.94  
   720x400       70.04  
   640x480       75.00    72.81    67.06    59.94    59.94  
DP-0 disconnected (normal left inverted right x axis y axis)

Ok… then I think it would work after you export DISPLAY=:1

I also do a single neural network for face detection.
Although the picture has appeared successfully.
But Error system message still appears

(process:27816): GStreamer-CRITICAL **: 20:51:59.966: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Opening in O_NONBLOCKING MODE

So we asked you if shared a full code in #10 and you told us it is the completed code.

May I know what are you doing exactly? What is your project? I think your error has nothing to do with the code you shared with us.

Hi,
Sorry, brother.
Originally used MobileNets for real-time face detection code
Found a system error
appear:
(Process: 27816): GStreamer - CRITICAL **: 20 : 51 : 59.966 : gst_element_get_state : Assertion ‘GST_IS_ELEMENT(element)’ failed
Nvbuf_utils : Can you get the connection shown by EGL?
Nvbuf_utils : Get the error of proc addr of eglCreateImageKHR
Nvbuf_utils : Get the error of proc addr of eglDestroyImageKHR
Nvbuf_utils : Can you get the connection shown by EGL?
Nvbuf_utils : Get the error of proc addr of eglCreateImageKHR
Nvbuf_utils : Get the error of proc addr of eglDestroyImageKHR
Open in O_NONBLOCKING mode

So suspect is a camera error.
Test simply turn on the camera capture code #1 code, thinking the error is this
Still executing a system error
appear:
(process:26631): GStreamer-CRITICAL **: 13:02:27.677: gst_element_get_state: assertion ‘GST_IS_ELEMENT (element)’ failed
Nvbuf_utils: Could not get EGL display connection
Nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
Nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Nvbuf_utils: Could not get EGL display connection
Nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
Nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Opening in O_NONBLOCKING MODE
But after solving the test #1 code yesterday, there was no error.
I thought it was solved, and to execute the real-time face detection code, an error still occurred.
Sorry for your troubles

Are you sure your MobileNet is able to read out the DISPLAY environment variable?

ㄜ…I do not know.
But at least it appears and completes the work I want

Could you try to run MMAPI sample installed from sdkmanager and run the sample?

Want to know if MMAPI sample would hit same error or not.