Hello everyone I am working with a Original Jetson nano. I want to use ros-foxy and openCV. However I was using the docker container with ros-foxy-base but after reboot the system I got the next error
cv2.imshow(window_name, image)
cv2.error: OpenCV(4.5.4) /home/ubuntu/build_opencv/opencv/modules/highgui/src/window_gtk.cpp:635: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'
I was using this container Jetson-container but The same problem happened. This is my run file
#!/usr/bin/env bash
# pass-through commands to 'docker run' with some defaults
# https://docs.docker.com/engine/reference/commandline/run/
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# check for V4L2 devices
V4L2_DEVICES=""
for i in {0..9}
do
if [ -a "/dev/video$i" ]; then
V4L2_DEVICES="$V4L2_DEVICES --device /dev/video$i "
fi
done
# check for display
DISPLAY_DEVICE=""
if [ -n "$DISPLAY" ]; then
# give docker root user X11 permissions
sudo xhost +si:localuser:root
# enable SSH X11 forwarding inside container (https://stackoverflow.com/q/48235040)
XAUTH=/home/windrobo/Documents/docker_xauth/.docker.xauth
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
chmod 777 $XAUTH
DISPLAY_DEVICE="-e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH"
fi
# check if sudo is needed
if id -nG "$USER" | grep -qw "docker"; then
SUDO=""
else
SUDO="sudo"
fi
# run the container
ARCH=$(uname -i)
if [ $ARCH = "aarch64" ]; then
# this file shows what Jetson board is running
# /proc or /sys files aren't mountable into docker
cat /proc/device-tree/model > /tmp/nv_jetson_model
set -x
$SUDO docker run --runtime nvidia -it --name windrobo --network host \
--volume /tmp/argus_socket:/tmp/argus_socket \
--volume /etc/enctune.conf:/etc/enctune.conf \
--volume /etc/nv_tegra_release:/etc/nv_tegra_release \
--volume $ROOT/data:/data \
--device /dev/snd \
--device /dev/bus/usb \
$DATA_VOLUME $DISPLAY_DEVICE $V4L2_DEVICES \
"$@"
elif [ $ARCH = "x86_64" ]; then
set -x
$SUDO docker run --gpus all -it --network=host \
--shm-size=8g \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--env NVIDIA_DRIVER_CAPABILITIES=all \
--volume $ROOT/data:/data \
$DATA_VOLUME $DISPLAY_DEVICE $V4L2_DEVICES \
"$@"
fi
Does anyone know how to fix this problem or has it happened to someone before ?
Would it be possible that something in your container updates python installed opencv version (with pip or else) ?
You may try adding the following lines at the beginning of your python script:
import cv2
print(cv2.getBuildInformation())
and see if the output is different from first run as compared to next runs.
Before spending much time digging into this further, please see the history of this issue on GitHub:
I believe it’s related to the same container instance being used after restart (there is no --rm used when container is started), and the /tmp files used for X11 changing. Since you can’t add mounts/volumes to container after it’s started, workaround is to start new container after reboot.