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

  • Practical Computer Vision
  • Abhinav Dadhich
  • 343字
  • 2021-06-30 18:54:45

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.

主站蜘蛛池模板: 绥芬河市| 巫山县| 三台县| 玛曲县| 彩票| 富川| 嵩明县| 工布江达县| 潞西市| 麻城市| 苍南县| 乌审旗| 五家渠市| 新田县| 东山县| 多伦县| 伽师县| 新乡县| 远安县| 天祝| 新和县| 武夷山市| 新竹县| 临邑县| 红桥区| 图们市| 独山县| 龙岩市| 深水埗区| 九寨沟县| 股票| 扎囊县| 尼勒克县| 崇阳县| 宁国市| 沈阳市| 奉贤区| 虎林市| 宁都县| 新建县| 拜泉县|