树莓派安装opencv3的问题及解决方式

本文转载自
[子豪兄教你在树莓派上安装OpenCV] http://suo.im/5gS6if
[ubuntu16.04安装opencv3.4.1时出现: libgtk2.0-dev : 依赖: libgtk2.0-0 (= 2.24.23-0ubuntu1) ]https://blog.csdn.net/u014527548/article/details/80251046
[Linux配置Xming+[Putty, Xshell,SecureCRT] 本地显示X11转发图像]
https://blog.csdn.net/u010472607/article/details/80356216

这里我只描述安装opencv3过程中遇到的一些问题,详细步骤请参见转载的原文。

1、安装numpy
numpy是python的一个科学计算处理库,在图像处理过程中会很有用。

sudo pip3 install numpy

2.在树莓派设置中把根目录扩大到整个SD卡
这里详细见http://suo.im/5gS6if

3、安装OpenCV所需的库

这里需要格外注意这里的所有库都要确保安装上

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
树莓派安装opencv3的问题及解决方式_第1张图片
QQ图片20181123233408.png

出现上图则说明安装成功。

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
 gstreamer0.10-ffmpeg : Depends: XXX but it is not going to be installed or
                                XXX but it is not going to be installed
 E: Unable to correct problems, you have held broken packages.

出现上图中则说明出现了依赖性问题,解决方式(假设是libgtk2.0-dev出问题。其他同类问题方法类似换掉安装的库就行),运行后会出现一大堆消息,给出第一个解决方案一般是保留这些库文件,让选择y/n/q?,这里选择“n”;然后会继续找解决方案,有时会超时找不到,点击y继续找,直到给出得解决方案是“降级”这些库文件,选择“y”,然后等待结束就完了

sudo aptitude install libgtk2.0-dev

详细见https://blog.csdn.net/u014527548/article/details/80251046
和https://www.cnblogs.com/zpc-uestc/p/6852173.html
确保所有库都安装上之后进行下一项。
4、下载OpenCV
这里详细见http://suo.im/5gS6if
5、设置编译参数
这里详细见http://suo.im/5gS6if
注意配置文件时需要更改一些路径


cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Downloads/opencv_contrib-3.4.0/modules -D BUILD_EXAMPLES=ON -D WITH_LIBV4L=ON PYTHON3_EXECUTABLE=/usr/bin/python3.5 PYTHON_INCLUDE_DIR=/usr/include/python3.5 PYTHON_LIBRARY=/usr/lib/arm-linux-gnueabihf/libpython3.5m.so PYTHON3_NUMPY_INCLUDE_DIRS=/home/pi/.local/lib/python3.5/site-packages/numpy/core/include ..

其中的numpy路径需要查看自己自己安装numpy的位置,通常如下:

PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include

6、编译
这里详细见http://suo.im/5gS6if
7、在Python3上测试OpenC
这里详细见http://suo.im/5gS6ifV

通过以上步骤一步一步的能够顺利的安装上opencv

最后在使用ssh远程运行opencv程序时如果出现图中使用cv2.imshow函数报错,且图片打不开时请按照此文
[Linux配置Xming+[Putty, Xshell,SecureCRT] 本地显示X11转发图像]
https://blog.csdn.net/u010472607/article/details/80356216解决

QQ图片20181124000614.png

再次感谢下列这些文章对我在树莓派上安装opencv3的帮助,本次安装过程历时五天。。。呜呜。。。本文集中了此次安装过程中的一些主要问题,希望能减少大家的安装时间。
[子豪兄教你在树莓派上安装OpenCV] http://suo.im/5gS6if
[ubuntu16.04安装opencv3.4.1时出现: libgtk2.0-dev : 依赖: libgtk2.0-0 (= 2.24.23-0ubuntu1) ]https://blog.csdn.net/u014527548/article/details/80251046
[Linux配置Xming+[Putty, Xshell,SecureCRT] 本地显示X11转发图像]
https://blog.csdn.net/u010472607/article/details/80356216

你可能感兴趣的:(树莓派安装opencv3的问题及解决方式)