insect-detect icon indicating copy to clipboard operation
insect-detect copied to clipboard

OAK camera preview script not working

Open Trematod opened this issue 1 year ago • 1 comments

Hello!

I'm trying to run the OAK camera preview script : https://maxsitt.github.io/insect-detect-docs/software/programming/ and I'm running into an issue : pi@camtrap1:~/insect-detect $ python3 cam_preview.py Unable to init server: Could not connect: Connection refused Traceback (most recent call last): File "/home/pi/insect-detect/cam_preview.py", line 98, in cv2.imshow("cam_preview", frame_lq) cv2.error: OpenCV(4.5.5) /tmp/pip-wheel-efxaz4j7/opencv-python_bedc0fac27944da0921e079da44d32bf/opencv/modules/highgui/src/window_gtk.cpp:635: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

Does anyone have an idea on how to make this work ? Thanks :)

Trematod avatar Jul 30 '24 14:07 Trematod

Hi @Trematod !

The Can't initialize GTK backend in function 'cvInitSystem' is most often caused by a missing step in the X11 forwarding setup. It indicates that OpenCV is not able to create a window to show the frames with cv2.imshow().

Please make sure that you have followed all steps under SSH connection and X11 forwarding, especially setting the DISPLAY environment variable and rebooting your PC afterwards. You also need an active VcXsrv X server by starting the XLaunch.exe application. Please make sure to use the -Y flag when connecting to your Raspberry Pi via ssh to enable trusted X11 forwarding.

I hope this helps, let me know if you have any further questions!

maxsitt avatar Aug 02 '24 11:08 maxsitt

It's working thanks!

Trematod avatar Aug 15 '24 06:08 Trematod

Hi I have this error: pi@insdet-cam01:~ $ python3 insect-detect/yolo_preview.py Traceback (most recent call last): File "/home/pi/insect-detect/yolo_preview.py", line 34, in import cv2 ModuleNotFoundError: No module named 'cv2' pi@insdet-cam01:~ $ python3 insect-detect/yolo_preview.py Traceback (most recent call last): File "/home/pi/insect-detect/yolo_preview.py", line 34, in import cv2 ModuleNotFoundError: No module named 'cv2'

NicolaF899 avatar Mar 17 '25 16:03 NicolaF899

Hi @NicolaF899 ,

with the updated instructions that now use RPi OS Bookworm, you installed all required packages in a virtual environment. You will have to use the Python interpreter from this virtual environment to run the scripts, e.g. with:

env_insdet/bin/python3 insect-detect/cam_preview.py

This was not updated yet in the Programming section. There are more major updates coming soon, after that I will update the whole Programming section on the documentation website as well.

However, I would recommend to use the new webapp.py script for optimized frame streaming and showing of the detection model + object tracker output. The opencv-based preview scripts will be deprecated soon.

Start the web app by running:

env_insdet/bin/python3 insect-detect/webapp.py

And open the link that is printed in the terminal (should be http://insdet-cam01:5000/).

Best, Max

maxsitt avatar Mar 18 '25 23:03 maxsitt

Hi, "It works with the web app, but now I've changed the camera (still the same one), and I'm getting this error — do you have any suggestions?"

Image

NicolaF899 avatar May 26 '25 15:05 NicolaF899

Hi @NicolaF899,

it seems like you are using the latest web app version but still an older config version without the https setting. Can you check if the https setting is included in your config file and use the latest version if not?

maxsitt avatar May 27 '25 10:05 maxsitt