Jetson.Utils.gldisplay() [OpenGL] failed to create X11 Window

Using Jetson Inference to identify parts, also using xml files(created using camera capture subprocess) to store regions of interest in which parts need to be counted, and using cv2 to draw the ROIs and put solid rectangles on top of the parts (because the customer asked us to even though the images aren’t being saved)

here’s my code:

import jetson.utils
import paho.mqtt.publish as publish
from threading import Timer
import time
import getpass
import xml.etree.ElementTree as ET
import cv2
import numpy as np
import jetson.inference

currentUser = getpass.getuser()

objFound1 = False
objFound2 = False

nameTopic = "inspection"
nameTopic_3 = "ct1"
nameTopic_4 = "ct2"
sMsg_0 = "good"
sMsg_1 = "reject"
sMsg_2 = ""
folderName = 'power'
tresh = '0.90'

className1 = "good"
className2 = "reject"
className3 = ""

mqtt_user = 'public'
mqtt_pw = 'public'
portNo = 1889
host = 'localhost'

cg = 0
cr = 0

l = 0
r = 0
t = 0
b = 0
x = 0
y = 0

class ROI:

	def __init__(self, name, w, h, xmin, ymin, xmax, ymax): = name
		self.w = w
		self.h = h
		self.xmin = xmin
		self.ymin = ymin
		self.xmax = xmax
		self.ymax = ymax
		self.count = 0

	def box(self,image,width,height):
		x1 = (self.xmin*width)/self.w
		y1 = (self.ymin*height)/self.h
		x2 = (self.xmax*width)/self.w
		y2 = (self.ymax*height)/self.h
		th = 10
		cl = (int(0),int(0),int(0))
		image = np.ascontiguousarray(image)
		image = cv2.rectangle(image.copy(), (int(x1),int(y1)), (int(x2),int(y2)), cl, int(th))
		return image

	def recount(self):
		self.count = 0

	def inside(self,width, height, x,y):
		x = (x*self.w)/width
		y = (y*self.h)/height
		if(x>self.xmin and x<self.xmax and y>self.ymin and y<self.ymax):
			self.count += 1

rois = []

txtf = open("people counting(onnx)/ImageSets/Main/train.txt","r")
for line in txtf:
	line = line.strip()
	tree = ET.parse("people counting(onnx)/Annotations/{}.xml".format(line))
	root = tree.getroot()
	size = root.find('size')
	w = int(size.find('width').text)
	h = int(size.find('height').text)
	for obj in root.findall('object'):
		name = obj.find('name').text
		box = obj.find('bndbox')
		xmin = int(box.find('xmin').text)
		ymin = int(box.find('ymin').text)
		xmax = int(box.find('xmax').text)
		ymax = int(box.find('ymax').text)

net = jetson.inference.detectNet(argv=['--model=/home/'+currentUser+'/jetson-inference/python/training/detection/ssd/models/'+folderName+'/ssd-mobilenet.onnx', '--labels=/home/'+currentUser+'/jetson-inference/python/training/detection/ssd/models/'+folderName+'/labels.txt', '--input-blob=input_0', '--output-cvg=scores', '--output-bbox=boxes', '--threshold='+tresh])

camera = jetson.utils.gstCamera(800, 600, "/dev/video0")
display = jetson.utils.glDisplay()

while display.IsStreaming():
	img, width, height = camera.CaptureRGBA(zeroCopy=1)
	detections = net.Detect(img, width, height)
	img2 = jetson.utils.cudaToNumpy(img,width,height,4)

	for detection in detections:
		l = detection.Left
		r = detection.Right
		t = detection.Top
		b = detection.Bottom
		th = -1
		cl = (int(0),int(255),int(0))
		img = np.ascontiguousarray(img)
		img = cv2.rectangle(img.copy(),(int(l),int(t)),(int(r),int(b)),cl,int(th))

	total = len(detections)
	titletext = "Flex Inspect | Network {:.0f} FPS, Total Count:{}".format(net.GetNetworkFPS(),total)
	for roi in rois:


		for detection in detections:
			class_name = net.GetClassDesc(detection.ClassID)
			l = detection.Left
			r = detection.Right
			t = detection.Top
			b = detection.Bottom
			x = l + (r-l)/2
			y = t + (b-t)/2

		titletext = titletext + ", {}:{}".format(,roi.count)
	img = jetson.utils.cudaFromNumpy(img)

I know nothing of the AI code, but you should include details of how the code is being run. Especially if this is run interactively from a GUI versus remote login or other display. Anything OpenGL failing to create a window will fail if there isn’t a display context, and many forms of remote login have no display context.

the code is not being run from a GUI or remote login, it is simply being run from the terminal, also, I tried using Jetson.utils.videoOutput(‘display.//0’) but that threw an error saying it required a file as input like an mp4.

here’s another thought I had, if it might be better to display the video using something like tkinter, since I have to convert the image to a numpy anyway to draw the ROIs and block the detected parts, that would mean not having to convert it back.

Try using jetson.utils.videoOutput('display://0') instead

jetson.utils.gldisplay() [OpenGL] failed to create X11 Window

I think there is an issue with importing cv2 where it messes up the GL/GLX bindings/extensions that jetson.utils uses. Can you try importing cv2 after you have created the glDisplay/videoOutput object? I understand that isn’t very pythonic, but it has seemed to work in the past.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.