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

时间:2019-07-03 13:51:48

标签: python opencv raspberry-pi

我已经尝试了很多天,用Raspbian Buster在我的Raspberry Pi 4上安装OpenCV,但我做不到。安装在大多数情况下都可以运行,但是在导入或使用cv2方法(例如cv2.imshow())时,会出现错误(请参见下文)。

有人让OpenCV在Raspberry Pi 4上工作还是对如何使其工作有想法?预先感谢您的帮助:-)!


使用pip安装OpenCV后出现错误:

s <- sqldf("select a.*, b.RESULT
  from df1 as a 
  left join df2 as b on a.id = b.id - 1")
transform(s, RESULT = paste0(sub(".$", "", RESULT), ID))

我无法安装此库“ libImath-2_2.so.12”。错误仍然存​​在。


使用conda安装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

我检查了库libgtk2.0-dev和pkg-config是否已经安装。我不知道如何以某种方式“在功能cvShowImage中配置脚本”。


通过编译安装OpenCV后出现错误

我经历了这两个指南中描述的编译过程。这些指南适用于我的Raspberry Pi 3b,但不适用于我的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/

我能够使用make,sudo make install等完成编译。此后,尽管现在我仍然必须将openCV安装链接到我的Python绑定。使用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 命令设置以下路径:

  • Python 3解释器:cmake
  • Python 3软件包:/home/pi/miniconda3/bin/python3 (ver 3.5.6)
  • Python(用于构建):lib/python3.5/dist-packages

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

在此先感谢您的帮助:-)!

保罗

5 个答案:

答案 0 :(得分:0)

您必须在make之后运行cmake。在下一步中,make install会在没有错误的情况下运行make

现在您可以在Python中使用OpenCV(假设您的配置有效)。 也许您必须重建opencv,因为您使用Python2.7进行了构建。 将PYTHON_DEFAULT_EXECUTABLE设置为Python3以将OpenCV与Python3结合使用: -DPYTHON_DEFAULT_EXECUTABLE=$(which python3)

答案 1 :(得分:0)

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

只需运行sudo apt install python3-opencv,它将运行,并使用cv2.imshow()创建窗口。

答案 2 :(得分:0)

对于opencv 4.3.0 raspberry pi 4 raspbian buster tbb neon

安装步骤

wget https://github.com/cyysky/OpenCV-Raspberry-Pi-4-Package-for-Python/raw/master/opencv_4.3.0-1_armhf.deb

sudo dpkg -i opencv_4.3.0-1_armhf.deb # This will install fail for dependency

sudo apt-get -f install # Auto install dependency package

sudo dpkg -i opencv_4.3.0-1_armhf.deb # Now start install

sudo apt-get install tesseract-ocr # Optional : tesseract-ocr

如果您有import issues

export LD_PRELOAD=$LD_PRELOAD:/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0

答案 3 :(得分:0)

首先有一个新鲜的新树莓

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4 
sudo apt-get install libqt4-test
sudo apt-get install libhdf5-dev
sudo pip3 install flask
sudo pip3 install numpy
sudo pip3 install opencv-contrib-python
sudo pip3 install imutils
sudo pip3 install opencv-python

答案 4 :(得分:0)

用户acine sachiro发布的I typed "advert" using "p" tag的版本略短(列表/字典理解)。

UPDATE t SET
  col1 = NVL(col1,0)
, col2 = NVL(col2,0)
, col3 = NVL(col3,0)
[...]
WHERE col1 IS NULL
   OR col2 IS NULL
   OR col3 IS NULL
[...]
;

执行命令的实际工作代码为:

import os

dct = {'apt-get'         : ['update', 'upgrade', 'other commands', 'etc.'],
       'apt-get install' : ['libatlas-base-dev','libjasper-dev', 'libqtgui4', 'libhdf5-dev'],
       'pip3 instal'     : ['flask', 'numpy', 'opencv-contrib-python', 'imutils', 'opencv-python']}

# The below code shows how nested list comprehension works

for k,v in dct.items():
    for i in v:
        print (k,i)

# which can be re-written to:

[print (k,i) for k,v in dct.items() for i in v]