温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - How can i make OpenCV work fully on Raspberry Pi 4 (Raspbian Buster)?

python - 我如何才能使OpenCV在Raspberry Pi 4(Raspbian Buster)上完全发挥作用?

发布于 2020-03-27 10:45:27

我已经尝试了很多天,用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:

  1. https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/
  2. https://www.learnopencv.com/install-opencv-4-on-raspberry-pi/

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:

  • Python 3 Interpreter: /home/pi/miniconda3/bin/python3 (ver 3.5.6)
  • Python 3 Packages: lib/python3.5/dist-packages
  • Python (for build): /usr/bin/python2.7

现在如何访问OpenCV,如何将其链接到Python,以便可以将其导入为cv2?

预先感谢您的帮助 :-)!

保罗

查看更多

查看更多

提问者
Paul Strobel
被浏览
44
Paul Strobel 2019-07-04 22:04

在@Ingo的帮助下,我终于可以用比预期的简单得多的解决方案在Raspbian Buster上安装OpenCV:

只需运行sudo apt install python3-opencv,它就可以工作,并且还可以使用cv2.imshow()创建窗口。

发布
问题

分享
好友

手机
浏览

扫码手机浏览