官术网_书友最值得收藏!

OpenCV build from source

Building OpenCV from source is quite a long process, depending on the hardware you are using: 

  • Requirements on Linux (here Ubuntu):
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

The following is an install script; copy the following snippet to install the install.sh file, and run bash install.sh to install OpenCV.

In the following code, replace $PATH_TO_ANACONDA with the absolute path to Anaconda, such as /Users/mac:

# download opencv 
wget https://github.com/opencv/opencv/archive/3.3.0.zip
unzip 3.3.0.zip
mv opencv-3.3.0 opencv
rm -rf 3.3.0.zip


# install opencv
cd opencv
mkdir build && cd build
cmake -D -DPYTHON_INCLUDE_DIR=$PATH_TO_ANACONDA/anaconda3/include/python3.6m/ \
-DPYTHON_EXECUTABLE=$PATH_TO_ANACONDA/anaconda3/bin/python \
-DPYTHON_PACKAGES_PATH=$PATH_TO_ANACONDA/anaconda3/lib/python3.6/site-packages \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DCMAKE_INSTALL_PREFIX=$PATH_TO_ANACONDA/anaconda3 \
-DWITH_QT=ON \
-DFORCE_VTK=ON \
-DWITH_GDAL=ON \
-DWITH_FFMPEG=ON \
-DWITH_TBB=ON \
-DWITH_XINE=ON \
-DWITH_OPENCL=OFF \
-DBUILD_EXAMPLES=ON ..

make -j4
make install

Since there are significant changes between OpenCV2 and OpenCV3, the code in this book is written using only OpenCV3.

In OpenCV, extra contributed modules are moved to a separate repository under the name opencv_contrib. In order to build OpenCV including with opencv_contrib , the steps are as follows:

  • Download OpenCV as :
# download opencv 
wget https://github.com/opencv/opencv/archive/3.3.0.zip
unzip 3.3.0.zip
mv opencv-3.3.0 opencv
rm -rf 3.3.0.zip
  • Download the extra module here, and note the path to this folder:
# opencv contrib code 
wget https://github.com/opencv/opencv_contrib/archive/3.3.0.zip
unzip 3.3.0.zip
mv opencv_contrib-3.3.0 opencv_contrib
rm -rf 3.3.0.zip
  • Build a complete OpenCV again, as follows, where PATH_TO_CONTRIB is the path to the previously downloaded opencv_contrib path:
cd opencv 
mkdir build && cd build
cmake -D -DOPENCV_EXTRA_MODULES_PATH=$PATH_TO_CONTRIB/opencv_contrib/modules \
-DPYTHON_INCLUDE_DIR=$PATH_TO_ANACONDA/anaconda3/include/python3.6m/ \
-DPYTHON_EXECUTABLE=$PATH_TO_ANACONDA/anaconda3/bin/python \
-DPYTHON_PACKAGES_PATH=$PATH_TO_ANACONDA/anaconda3/lib/python3.6/site-packages \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DCMAKE_INSTALL_PREFIX=$PATH_TO_ANACONDA/anaconda3 \
-DWITH_QT=ON \
-DFORCE_VTK=ON \
-DWITH_GDAL=ON \
-DWITH_FFMPEG=ON \
-DWITH_TBB=ON \
-DWITH_XINE=ON \
-DWITH_OPENCL=OFF \
-DBUILD_EXAMPLES=ON ..

make -j4
make install

Here, we see that there are several options which are set on or off. The choice of these operations depends on the availability of the dependencies. These can be set to on if all of the dependencies are available.

主站蜘蛛池模板: 彰化县| 新丰县| 靖安县| 莆田市| 桐柏县| 吴桥县| 扎兰屯市| 伊金霍洛旗| 巴彦县| 门头沟区| 措勤县| 博罗县| 炎陵县| 大兴区| 团风县| 安新县| 天门市| 即墨市| 常山县| 定安县| 宝坻区| 建湖县| 克拉玛依市| 商水县| 泾川县| 阿荣旗| 铁岭县| 龙山县| 江口县| 和平区| 游戏| 恩施市| 渝中区| 焉耆| 瑞昌市| 全南县| 常熟市| 肥城市| 临朐县| 徐汇区| 孟连|