Skip to content

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' #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
magsol opened this issue Feb 12, 2022 · 4 comments

Comments

@magsol
Copy link

magsol commented Feb 12, 2022

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.

@Clark1216
Copy link

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

@magsol
Copy link
Author

magsol commented Feb 22, 2022

@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.

@armindocachada
Copy link
Owner

armindocachada commented Feb 23, 2022 via email

@magsol
Copy link
Author

magsol commented Feb 23, 2022

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants