0%

树莓派安装OpenCV3

源码安装

这种方式编译时间巨长,然鹅我重试了3次还是没有成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
sudo apt-get install build-essential git cmake pkg-config -y
sudo apt-get install libjpeg8-dev -y
sudo apt-get install libtiff5-dev -y
sudo apt-get install libjasper-dev -y
sudo apt-get install libpng12-dev -y

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y

sudo apt-get install libgtk2.0-dev -y
sudo apt-get install libatlas-base-dev gfortran -y


wget https://github.com/Itseez/opencv/archive/3.4.0.zip
mv 3.4.0.zip opencv-3.4.0.zip

wget https://github.com/Itseez/opencv_contrib/archive/3.4.0.zip
mv 3.4.0.zip opencv_contrib-3.4.0.zip

unzip opencv-3.4.0.zip
unzip opencv_contrib-3.4.0.zip

mkdir build
cd build
sudo make
sudo make install

pip3

这个方式可以说是最简单的了..

1
sudo pip3 install opencv-python

import的时候报了一个错

1
2
3
4
5
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *

然后全运行一遍再import就成功了

1
2
3
4
5
sudo apt-get install libhdf5-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqt4-test
sudo apt-get install libqtgui4

参考

Have fun.