Exception: jetson.utils -- failed to create glDisplay device

I’m trying to run a simple detection/segmentation on an AGX Xavier + an Intel Realsense camera. The code is similar to the one found in the tutorials (). Everything goes well until attempting to import cv2, at which point I get the following error:

[…]
segNet – loaded 21 class colors
jetson.utils – PyDisplay_New()
jetson.utils – PyDisplay_Init()
[OpenGL] glDisplay – X screen 0 resolution: 1920x1080
[OpenGL] failed to create X11 Window.
jetson.utils – PyDisplay_Dealloc()
Traceback (most recent call last):
File “/home/xavier/<…>”, line 79, in
display = jetson.utils.glDisplay()
Exception: jetson.utils – failed to create glDisplay device

Note: The Xavier is connected to a display on the HDMI port, as I’ve found similar posts with the same issue that were running it headless.

SW:
JetPack 4.4
Removed OpeCV 4 and built 3.4.3, as I thought that might the issue

code:

import cv2

import pyrealsense2 as rs
import numpy as np
import jetson.inference
import jetson.utils
import argparse
import ctypes
import sys

[…parse the command line…]

try:
opt = parser.parse_known_args()[0]
except:
print("")
parser.print_help()
sys.exit(0)

net = jetson.inference.segNet(opt.network, sys.argv)

net.SetOverlayAlpha(opt.alpha)

img_overlay = jetson.utils.cudaAllocMapped(opt.width * opt.height * 4 * ctypes.sizeof(ctypes.c_float))

pipeline = rs.pipeline()
config = rs.config()

config.enable_stream(rs.stream.depth, opt.width, opt.height, rs.format.z16, 30)
config.enable_stream(rs.stream.color, opt.width, opt.height, rs.format.rgba8, 30)
pipeline.start(config)

display = jetson.utils.glDisplay()

while display.IsOpen():
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
if not color_frame:
continue
color_image = np.asanyarray(color_frame.get_data())
cuda_frame = jetson.utils.cudaFromNumpy(color_image)
net.Process(cuda_frame, opt.width, opt.height, opt.ignore_class)
net.Overlay(img_overlay, opt.width, opt.height, opt.filter_mode)
display.BeginRender()
display.Render(img_overlay, opt.width, opt.height)
display.EndRender()
display.SetTitle("{:s} | Network {:.0f} FPS | Display {:.1f} FPS".format(opt.network, net.GetNetworkFPS(),
display.GetFPS()))

What happens if you import cv2 after the glDisplay object is created?

I realize that isn’t ideal, but there seems to be some conflict between the two where perhaps cv2 is loading it’s own GL extension manager or something along those lines.

Also, the jetson-utils video input/output interfaces have been updated in the latest master, see here for examples of using them:

Note that the previous interfaces do continue to work if you prefer using them.

1 Like