python - 如何让 OpenCV 在 Raspberry Pi 4 (Raspbian Buster) 上完全运行?
问题描述
我已经尝试了很多天使用 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:
- https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/
- https://www.learnopencv.com/install-opencv-4-on-raspberry-pi/
我能够使用 make、sudo make install 等完成编译。之后,尽管我现在仍然必须将 openCV 安装链接到我的 Python 绑定。使用cmake
命令我设置以下路径:
- Python 3 解释器:
/home/pi/miniconda3/bin/python3 (ver 3.5.6)
- Python 3 包:
lib/python3.5/dist-packages
- Python(用于构建):
/usr/bin/python2.7
我现在如何访问 OpenCV,如何将其链接到 Python,以便将其作为 cv2 导入?
预先感谢您的帮助 :-)!
保罗
解决方案
在@Ingo 的帮助下,我终于能够在 Raspbian Buster 上安装 OpenCV,其解决方案比预期的简单得多:
只需运行sudo apt install python3-opencv
它就可以工作,还可以使用 cv2.imshow() 创建窗口。
推荐阅读
- webpack - Webpack 样式加载器和索引在 IDE 中生成的 sass 代码
- java - 如何调用 searchBook 方法来查找作为 donatedBy 数据属性捐赠的书籍
- powershell - 为什么 PSGallery 的脚本没有 Zone.Identifier 流?
- jenkins - Jenkins 声明式管道嵌入式库包括
- python - 如何在 Python 中共享对象数组
- kotlin - 多个全局范围有问题
- perforce - 关于 Perforce 的多个问题
- github - 如何在仍有通配符的情况下忽略 GitHub CODEOWNERS 中的文件
- apexcharts - Apexchart 气泡图:连接气泡的线
- python - 如何使用嵌套的 for 循环在 Python 中从一个列表写入另一个列表?