Use cv2.imshow() on Jetson NX 16 GB dev kit (Jetpack 5.0.1) inside a docker container

I have a Jetson NX 16GB dev kit with Jetpack 5.0.1 as OS. As a base image for my docker container I use nvcr.io/nvidia/l4t-pytorch:r34.1.1-pth1.12-py3. My opencv version inside the container is 4.5.5.

Before I start my container I run “xhost +” in the terminal. I run my container with the following flags:

docker run -it --rm \
    -v "$HOME/.Xauthority:/root/.Xauthority:rw" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    --runtime=nvidia \
    --net=host \
    -e LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1 \
    -e DISPLAY=$DISPLAY \
    --privileged \
    my_image:latest

The --privileged flag only worked after I changed the l4t.csv according to this post: Error running privileged L4T containers with the NVidia Runtime on JetPack 5.0 Developer Preview - #10 by AastaLLL. However, as soon as I want to use cv2.imshow() an error occurs. So I want to execute the following code:

import cv2

image = cv2.imread("/img/snapshot.png")
cv2.imshow("img", image)

and this is the output (I used QT_DEBUG_PLUGINS=1 beforehand):

QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Aborted (core dumped)

Nevertheless it is strange that if I use a tool like shotwell:

apt install shotwell
shotwell /img/snapshot.png

the image opens without any problem. I can also open a camerastream with arv-viewer. So my question is: How can I open a .png file with cv2.imshow inside my container? Is there a problem with cv2, have I missed a library or is this a bug from another type?

Thanks in advance for your help.

Hi,

Could you try if setting the $DISPLAY value within the container helps?
For example:

$ export DISPLAY=:0

Thanks.

I tried to set de DISPLAY variable to :0 and afterwards to :1, because it is :1 on the jetson locally. Regretably none of those settings has changed the error.

Hi,

We can open the window with the following steps.
(Please update :0 to the corresponding based on your environment)

$ export DISPLAY=:0
$ xhost +
$ sudo docker run -it --rm --runtime nvidia --network host nvcr.io/nvidia/l4t-pytorch:r35.1.0-pth1.12-py3

Within container:

$ export DISPLAY=:0
$ python3
>>> import numpy as np 
>>> import cv2
>>> x = np.ones((480,640),dtype=np.int8)
>>> cv2.imshow('test', x)
>>> cv2.waitKey(0)

Thanks.

Thank you for the hint. I had a different opencv version installed and I think that was my problem.

Thanks for the update.
Good to know you find the cause.

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