我已经尝试了很多天,用Raspbian Buster在我的Raspberry Pi 4上安装OpenCV,但是我做不到。在大多数情况下,安装都能正常工作,但是在导入或使用cv2方法(例如cv2.imshow())时,会出现错误(请参见下文)。
是有人让OpenCV在Raspberry Pi 4上工作还是对如何使其工作有想法?预先感谢您的帮助 :-)!
用pip安装OpenCV后出现错误:
pip install opencv-python
pip install opencv-contrib-python
python
>>> import cv2
ImportError: libImath-2_2.so.12: cannot open shared object file: no such file or directory
我无法安装此库“ libImath-2_2.so.12”。错误仍然存在。
使用conda安装OpenCV后出现错误:
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
I checked and the libraries libgtk2.0-dev and pkg-config were installed already. I don't know how to "configure the script in function cvShowImage" in a way that would make it work.
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:
I was able to finish the compilation with make, sudo make install etc. Afterwards though i now still have to link the openCV installation to my Python bindings. With the cmake
command i set the following paths:
/home/pi/miniconda3/bin/python3 (ver 3.5.6)
lib/python3.5/dist-packages
/usr/bin/python2.7
现在如何访问OpenCV,如何将其链接到Python,以便可以将其导入为cv2?
预先感谢您的帮助 :-)!
保罗
在@Ingo的帮助下,我终于可以用比预期的简单得多的解决方案在Raspbian Buster上安装OpenCV:
只需运行sudo apt install python3-opencv
,它就可以工作,并且还可以使用cv2.imshow()创建窗口。
@JakobHarderHolmelund您得到什么错误消息?