我已经尝试了很多天,用 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
我检查并已经安装了库 libgtk2.0-dev 和 pkg-config。我不知道如何以使其工作的方式“在函数 cvShowImage 中配置脚本”。
通过编译安装 OpenCV 后出错
我经历了这两个指南中描述的编译过程。这些指南适用于我的 Raspberry Pi 3b,但不适用于我的 Raspberry Pi 4:
我能够使用 make、sudo make install 等完成编译。之后,尽管我现在仍然必须将 openCV 安装链接到我的 Python 绑定(bind)。与
cmake
命令我设置以下路径:/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() 创建窗口。
关于python - 如何让 OpenCV 在 Raspberry Pi 4 (Raspbian Buster) 上完全运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56871700/