您可以省去如下步骤,直接下载我编译好的:
http://download.csdn.net/detail/u011258240/9710331
一、编译opencv2.4 不带contrib
1. 下载opencv源码
2. 将opencv 源码放在linux 的一个文件夹下(记得不要放在共享文件夹下,不然会出现软链接的错误)
3. opencv目录下新建文件夹 release ( 注:如果是3.3版本,还要删除这两个文件,很关键 rm -rf CMakeCache.txt CMakeFiles, 如果cmake版本低还要更新cmake版本 :https://launchpad.net/ubuntu/+source/cmake/3.9.1-1)
4.新建opencv的安装文件夹,例如mkdir /opencv1
5. cd release
cmake ../ \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/opencv3.3 \
-DWITH_TBB=1 \
-DWITH_PNG=1 \
-DWITH_TIFF=1 \
-DWITH_JPEG=1 \
-DWITH_JASPER=1 \
-DBUILD_SHARED_LIBS=0 \
-D INSTALL_C_EXAMPLE=OFF \ -D INSTALL_PYTHON_EXAMPLE=OFF \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \ -D BUILD_EXAMPLES=ON ..
cmake ../ -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/opencv3.3 -DWITH_TBB=1 -DWITH_PNG=1 -DWITH_TIFF=1 -DWITH_JPEG=1 -DWITH_JASPER=1 -DBUILD_SHARED_LIBS=0
6. make
7, make install
然后查看文件夹opencv1,显示生成了静态库
root@lyj:/opencv1# ls lib
libopencv_calib3d.a libopencv_flann.a libopencv_legacy.a libopencv_ocl.a libopencv_ts.a
libopencv_contrib.a libopencv_gpu.a libopencv_ml.a libopencv_photo.a libopencv_video.a
libopencv_core.a libopencv_highgui.a libopencv_nonfree.a libopencv_stitching.a libopencv_videostab.a
libopencv_features2d.a libopencv_imgproc.a libopencv_objdetect.a libopencv_superres.a pkgconfig
8. 特别注意:opencv 编译的静态库并不包含libpng.a libjpeg 等库,这些库也要自己编译。
9. 静态库的使用:记得一定要包含如下库,不然使用可能会出问题
-llibjasper
-llibjpeg \
-llibpng \
-lIlmImf \
-llibtiff \
-ldl \
-lz \
二、 编译opencv3.3 + contrib 静态库
cd opencv-3.3.0
mkdir build
cd build
cmake ../ \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/opencv3.3 \
-DBUILD_SHARED_LIBS=0 \
-DINSTALL_C_EXAMPLE=OFF \
-DINSTALL_PYTHON_EXAMPLE=OFF \
-DENABLE_SSE=ON \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.3.0/modules \
-DBUILD_EXAMPLES=OFF