I have tried many days to install OpenCV on my Raspberry Pi 4 with Raspbian Buster but i couldn't get it done. The installation always works but when importing or using cv2 methods like cv2.imshow(), errors come up (see below).
Did somebody get OpenCV working on a Raspberry Pi 4 or has an idea on how to get it working? Thank you in advance for your help :-)!
Error after installing OpenCV with pip:
pip install opencv-python pip install opencv-contrib-python python >>> import cv2 ImportError: libImath-2_2.so.12: cannot open shared object file: nu such file or directory
Error after installing OpenCV with conda:
conda install -c conda-forge opencv conda install -c conda-forge opencv=4.1.0 conda install -c menpo opencv python >>> import cv2 >>> img = cv2.imread("image.png", 0) >>> cv2.imshow("Frame", img) OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/jhelmus/conda/conda-bld/opencv_1512174356192/work/modules/highgui/src/window.cpp, line 605 Traceback (most recent call last): File "detect_video.py", line 113, in <module> cv2.imshow("Frame", img_main) cv2.error: /home/jhelmus/conda/conda-bld/opencv_1512174356192/work/modules/highgui/src/window.cpp:605: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
Error after installing OpenCV by compiling it
I went through the compilation processes described in these two guides. These guides worked on my Raspberry Pi 3b, but not on my Raspberry Pi 4:
After the process from the
make command reached almost the end, it could not link the openCV installation to the Python executable (neither the Python executable in my conda virtual environment
/home/pi/miniconda3/envs/py35/lib/python3.5, nor the global Python3 executable
/usr/bin/python3. The errors were somehow like "Permission denied: Could not access Python3.5". I used this cmake setting:
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -D BUILD_opencv_python3=yes \ -D PYTHON_DEFAULT_EXECUTABLE=/home/pi/miniconda3/envs/py35/lib/python3.5 \ -D OPENCV_PYTHON3_INSTALL_PATH=/home/pi/miniconda3/envs/py35/lib/python3.5/site-packages \ -D ENABLE_NEON=ON \ -D ENABLE_VFPV3=ON \ -D BUILD_TESTS=OFF \ -D OPENCV_ENABLE_NONFREE=ON \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D BUILD_EXAMPLES=OFF ..
I once tried this cmake command with the
PYTHON_DEFAULT_EXECUTABLE = /usr/bin/python3.
Thank you in advance for your help :-)!