Qengineering/Install-OpenCV-Raspberry-Pi-64-bits

OpenCV installation using Thonny on RPi 4 & removing

Petros626 opened this issue · 7 comments

Hello guys,

I'm glad I've found your articles on your website. I want to ask why I can use OpenCV in the Python terminal e.g.:

import cv2
cv.waitKey(1)
>>>-1

The problem is the use of the basic interpreter usr/bin/python3 under the Thonny IDE. Strangely enough I can't use any OpenCV function there. I tried so much ways to install it properly, but every time I wanted to use it in my IDE it can be imported, but not really used.

A second question is about the deinstallation, after using one of your scripts (e.g. OpenCV-4-7-0.sh). How can I remove everything, which has been installed?

Thanks in advance

$ sudo rm -rf /usr/local/bin/opencv*
$ sudo rm -rf /usr/local/bin/setup_vars_opencv4.sh
$ sudo rm -rf /usr/local/lib/aarch64-linux-gnu/libopencv*
$ sudo rm -rf /usr/local/lib/aarch64-linux-gnu/pkgconfig/opencv4.pc
$ sudo rm -rf /usr/local/lib/aarch64-linux-gnu/cmake/opencv4
$ sudo rm -rf /usr/local/include/opencv4
$ sudo rm -rf /usr/local/share/opencv4

Thank you for clarify the deinstallation. Could you dig further to the first issue I got? The installation of OpenCV did only work, when im using sudo apt install -y python3-opencv opencv-data

In that case you have installed a (regular) Python version of OpenCV.
In other words, your version is only suitable for Python programs, not C++.
If you want to program OpenCV with C++ you need the installation presented here.

In that case you have installed a (regular) Python version of OpenCV. In other words, your version is only suitable for Python programs, not C++. If you want to program OpenCV with C++ you need the installation presented here.

Yes, but the point is, that your recommended installation with for example ./OpenCV-4-7-0.sh is ok, but it doesn't work with the IDE like the above mentioned command. There is no behaviour when running code. Is there some linking issues or you got a tutorial where your working with OpenCV in the Thonny IDE or generally on RPi?

You need to add an extra sym link before Thonny can find OpenCV.

cd ~
sudo ln -s /usr/lib/python3/dist-packages/cv2 ./.config/Thonny/plugins/lib/python3.9/site-packages/cv2

image

Did you installed additional OpenCV for Thonny, because normally the site-packages folder under plugins don't contain cv2.

I've used the OpenCV installation presented in this repo. Let's call it the C++ version.
Once installed, there is a folder /usr/lib/python3/dist-packages/cv2 created.

By using a symbolic link command ln -s I create a link in the folder ./.config/Thonny/plugins/lib/python3.9/site-packages/
That's one of the folders Thonny is looking for additional libraries or packages.
After the symlink command you have the cv2 folder, marked with an arrow, indication the folder is in fact a link.