#先安装 cmake 3.14
# cmake安装到了 /usr/local/bin
#配置PATH
export PATH="$PATH:/usr/local/bin"
#下载最新的opencv
git clone "https://github.com/opencv/opencv.git"
git clone "https://github.com/opencv/opencv_contrib.git"
#定义自己的生成目录
mkdir 20190508mkdir -p opencv-master/buildcd opencv-master/build#生成配置的时候选择带上opencv-contrib
cmake -DOPENCV_EXTRA_MODULES_PATH=/home/admin/opencv/opencv_contrib-master/modules ..
#执行ccmake,配置编译选项
ccmake ..
#我配置的主要选项如下:
1 BUILD_DOCS:BOOL=OFF 2 BUILD_EXAMPLES:BOOL=OFF 3 BUILD_IPP_IW:BOOL=OFF 4 BUILD_ITT:BOOL=OFF 5 BUILD_JASPER:BOOL=OFF 6 BUILD_JAVA:BOOL=OFF 7 BUILD_JPEG:BOOL=OFF 8 BUILD_OPENEXR:BOOL=OFF 9 //Build performance tests10 BUILD_PERF_TESTS:BOOL=OFF11 //Build libpng from source12 BUILD_PNG:BOOL=OFF13 //Force to build libprotobuf from sources14 BUILD_PROTOBUF:BOOL=OFF15 //Build shared libraries (.dll/.so) instead of static ones (.lib/.a)16 BUILD_SHARED_LIBS:BOOL=OFF17 //Download and build TBB from source18 BUILD_TBB:BOOL=OFF19 //Build accuracy & regression tests20 BUILD_TESTS:BOOL=OFF21 //Build libtiff from source22 BUILD_TIFF:BOOL=OFF23 //Build WebP from source24 BUILD_WEBP:BOOL=OFF25 //Build utility applications (used for example to train classifiers)26 BUILD_opencv_apps:BOOL=OFF27 //Include opencv_face module into the OpenCV build28 BUILD_opencv_face:BOOL=OFF29 //Include opencv_highgui module into the OpenCV build30 BUILD_opencv_highgui:BOOL=OFF31 //Include opencv_java_bindings_generator module into the OpenCV32 // build33 BUILD_opencv_java_bindings_generator:BOOL=OFF34 //Build JavaScript bindings by Emscripten35 BUILD_opencv_js:BOOL=OFF36 //Include opencv_xfeatures2d module into the OpenCV build37 BUILD_opencv_xfeatures2d:BOOL=OFF38 //Installation Directory39 CMAKE_INSTALL_PREFIX:PATH=/home/admin/opencv/2019050840 41 //Include NVidia Cuda Runtime support42 WITH_CUDA:BOOL=OFF43 44 //Include Intel IPP support45 WITH_IPP:BOOL=OFF46 47 //Include Intel ITT support48 WITH_ITT:BOOL=OFF49 50 //Include JPEG2K support51 WITH_JASPER:BOOL=OFF52 53 //Include JPEG support54 WITH_JPEG:BOOL=OFF55 56 //Include Lapack library support57 WITH_LAPACK:BOOL=OFF58 59 //Include ILM support via OpenEXR60 WITH_OPENEXR:BOOL=OFF61 62 //Include PNG support63 WITH_PNG:BOOL=OFF64 65 //Build with Qt Backend support66 WITH_QT:BOOL=OFF67 68 //Include Intel TBB support69 WITH_TBB:BOOL=OFF70 71 //Include TIFF support72 WITH_TIFF:BOOL=OFF73 74 //Include Vulkan support75 WITH_VULKAN:BOOL=OFF76 77 //Include WebP support78 WITH_WEBP:BOOL=OFF
配置有这样一些考虑:
1.仅满足linux下的基本的图形处理的使用;
2.不要CUDA,不要各种图形格式的支持;3.生成静态库,避免多人使用的情况下大家相互覆盖;4.生成在自己的目录下,不放在系统目录。配置完成后按g,生成配置,退出。
make -j 20
make install
等到链接具体的程序的时候,还需要额外的一些库:
gcc -o xxx_elf xxx.o -L"/home/admin/opencv/20190508/lib64" -lopencv_core -lopencv_imgproc -lopencv_imgcodecs \-ldl -lz -pthread