raspberrypi-docker-tensorflow-opencv icon indicating copy to clipboard operation
raspberrypi-docker-tensorflow-opencv copied to clipboard

cv2.error: OpenCV(4.5.0) /root/opencv-4.5.0/modules/highgui/src/window_gtk.cpp:624: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

Open magsol opened this issue 3 years ago • 4 comments

When I run python3 example3.py, I get an error:

Traceback (most recent call last):
  File "example3.py", line 14, in <module>
    cv2.imshow('frame',frame)
cv2.error: OpenCV(4.5.0) /root/opencv-4.5.0/modules/highgui/src/window_gtk.cpp:624: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

It seems like the display isn't initialized and can't pop up the video viewer. The X11 server seems to check out everywhere so I'm not sure what I'm doing wrong.

If there isn't a need to pop up a window (e.g. in example2.py) it works just fine. So it's definitely something with X forwarding but I'm not sure where to look, as I've never really had much success with GUIs in Docker containers.

magsol avatar Feb 12 '22 00:02 magsol

You can try type in Xhost + in terminal before entering docker container

Clark1216 avatar Feb 22 '22 06:02 Clark1216

@Clark1216 I tried xhost + and Xhost + in the raspberry pi terminal before entering the docker container. The latter did not recognize the command; the former gave:

xhost:  unable to open display ""

and then when I entered the docker container and ran python3 example3.py it threw the same error message.

For context: my base machine is macOS. I'm using XQuartz to ssh into my raspberry pi. From that terminal, I enter the docker container.

magsol avatar Feb 22 '22 18:02 magsol

Hi Shannon,

It looks like you don't have the DISPLAY variable set. I normally use Remote Desktop to access the Raspberry Pi, and from there I can open the camera.

Kind regards Armindo

armindocachada avatar Feb 23 '22 07:02 armindocachada

@armindocachada It occurs to me that the OS version I have running is Raspberry Pi OS Lite, which I believe does not have a desktop interface. Would this impact this process?

How would I go about setting the DISPLAY variable? Would it be on the Pi itself, or in the Docker container?

magsol avatar Feb 23 '22 14:02 magsol