picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

Can't use picamera2 in a Tkinter GUI

Open Carl0sC0elh0 opened this issue 1 year ago • 5 comments

Hello everyone, I'm developing a Tkinter app to help me with some image processing. My objective is to take a photo from the picamera v3 module and store it for further analysis. the problem is that the code doens't run and aborts the app with this output

QObject::moveToThread: Current thread (0x7f580286a0) is not the object's thread (0x7f581f82b0). `Cannot move to target thread (0x7f580286a0)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/Carlos/FISCHER/lib/python3.11/site-packages/cv2/qt/plugins" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

I'm trying to use threading as well so that the tkinter app keeps running while the camera takes the shot, but even without threading the app closes when it reaches the segment to take a shot. Any advice on this? Is it a dependencies problem? Thanks in advance

Carl0sC0elh0 avatar Feb 01 '24 17:02 Carl0sC0elh0

Tkinter is not supported on Wayland (default on Pi3b+, Pi4 and Pi5). You need to be running X11. On Bookworm run raspi_config, goto Advanced Settings, Select Wayland and select X11 and Openbox. I do not know if this relevent to your issue.

tvoverbeek avatar Feb 01 '24 19:02 tvoverbeek

Are you able to post a really short and simple self-contained snippet of code (preferably just a dozen lines or so) that would allow others to reproduce the problem easily? That would make it easier to understand and help. Thanks.

davidplowman avatar Feb 02 '24 06:02 davidplowman

I solved a similar problem using Pygame. This actually works quite well. https://github.com/raspberrypi/picamera2/issues/607#issuecomment-1730933656

bnd762 avatar Feb 05 '24 10:02 bnd762

Thank you all for your suggestions but it was indeed a dependencies conflict or something like that. My venv didn't have picamera2 and libcamera2 installed and when installed (couldn't use pip, idon't know why), they had missing packages. I solved it by creating a new venv with --system-site-packages. Is it a good fix? I don't know, im just a noob with a PI4.

Thank you all and have a good week!

Carl0sC0elh0 avatar Feb 05 '24 10:02 Carl0sC0elh0

Yes, the easiest solution for a venv (unless you have some very particular requirements which mean it isn't appropriate) is to use --system-site-packages.

davidplowman avatar Feb 05 '24 11:02 davidplowman