raspberrypi-docker-tensorflow-opencv
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'
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.
You can try type in Xhost +
in terminal before entering docker container
@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.
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 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?