mynote/opencv/install.md
2018-09-16 11:16:52 +08:00

145 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# opencv 环境部署指南
> http://blog.csdn.net/cocoaqin/article/details/78163171
> http://blog.csdn.net/eds95/article/details/78870194
## ubuntu
``` bash
unzip opencv-3.3.0.zip
cd opencv
sudo apt install cmake
sudo apt install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
mkdir my_build
cd my_build
## cmake 中会下载安装一个大文件,网速会很慢
cmake -D CMAKE_BUILD_TYPE=Release \
-D OPENCV_EXTRA_MODULES_PATH=/home/lab/program/opencv_contrib-3.3.0/modules \
-D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
# add this
"
/usr/local/lib
"
sudo ldconfig
sudo gedit /etc/bash.bashrc
# add this
"
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
"
source /etc/bash.bashrc
sudo updatedb
# test
cd opencv***/smaples/cpp/example_cmake
cmake .
make
./opencv_example
# and you will see yourself
# compete
# sudo pip install numpy opencv-python
```
## raspberry
``` bash
sudo apt update
sudo apt upgrade
sudo rpi-update
sudo reboot
# 图像io库
sudo apt install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
# 视频处理库
sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt install libxvidcore-dev libx264-dev
# 安装gtk 用于opencv gui显示
sudo apt install libgtk2.0-dev
sudo apt install libatlas-base-dev gfortran
# 安装python 环境
sudo apt-get install python-dev python3-dev
sudo apt-get install build-essential libssl-dev libevent-dev libjpeg-dev libxml2-dev libxslt-dev
unzip ....
cd opencv
mkdir build
cd build
# warning change your path
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
# 修改swap空间大小
vi /etc/dphys-swapfile
# 找到CONF_SWAPSIZE=100改为1024
# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=1024
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
make -j4
sudo make install
sudo ldconfig
xhost +
export DISPLAY=:0.0
```
## cross compile
> referring https://blog.csdn.net/sun_28/article/details/52760463
> referring https://docs.opencv.org/master/d0/d76/tutorial_arm_crosscompile_with_cmake.html
> referring http://shumeipai.nxez.com/2013/10/08/configure-cross-compiler-platform-raspberry-pi.html
``` bash
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev
mkdir cross_compile_raspberry
cd cross_compile_raspberry/
git clone git://github.com/raspberrypi/tools.git --depth=1
unzip opencv.zip ./
cd opencv
mkdir build
cd build
sudo apt-get install cmake-qt-gui
cmake-gui
```