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

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.

主站蜘蛛池模板: 禹州市| 伊通| 灵宝市| 长治市| 湖州市| 通山县| 绥宁县| 那坡县| 莎车县| 施甸县| 丰顺县| 柳河县| 依兰县| 崇礼县| 三门峡市| 绵阳市| 东阿县| 满洲里市| 嘉义市| 潮安县| 那曲县| 滁州市| 大理市| 南京市| 冕宁县| 神池县| 综艺| 晋宁县| 峨边| 临海市| 宣威市| 江津市| 鞍山市| 岳池县| 绿春县| 合阳县| 青龙| 吴堡县| 锡林郭勒盟| 错那县| 永春县|