1.下载好Opencv3.4.1与对应版本的Opencv_contrib3.4.1:
https://github.com/opencv
并把opencv_contrib文件放到opencv3.4.1文件夹下,并在这个文件夹下建立build文件夹
2.安装必要依赖项(虽然不知道干吗用的,不安装编译通不过,而且报莫名其妙的错误):
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 python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install build-essential qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
2.按照readme所述:
我安装在/opencv3.4.1/usr/下
cd build
cmake -DOPENCV_EXTRA_MODULES_PATH=/home/luoyongheng/opencv-3.4.1/opencv_contrib-3.4.1/modules -DCMAKE_INSTALL_PREFIX=/opencv3.4.1/usr/ ..
make -j16
3.各种报错:
a.cmake时候一直卡在下载项,自己去寻找对应的包,放到对应的位置,涉及到face_landmark_model.dat,ippicv,tiny_dnn
等,tiny_dnn这个github地址已失效,需要从csdn上下载,并修改对应的CNakeLists.txt文件。
b.如果出现报错:libopencv_highgui.so:undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
sudo apt-get install libtiff4-dev
cmake -DOPENCV_EXTRA_MODULES_PATH=/home/luoyongheng/opencv-3.4.1/opencv_contrib-3.4.1/modules -DCMAKE_INSTALL_PREFIX=/opencv3.4.1/usr/ -DBUILD_TIFF=ON ..
c.C++11支持报错,在报错的包中,添加C++11支持:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
d.与内核有关的报错:
/tmp/cc8j8kGs.s: Assembler messages:
/tmp/cc8j8kGs.s:205: 错误: operand type mismatch for `vxorps'
/tmp/cc8j8kGs.s:278: 错误: no such instruction: `vextractf32x8 $0x1,%zmm7,%ymm0'
/tmp/cc8j8kGs.s:280: 错误: no such instruction: `vextractf32x8 $0x1,%zmm6,%ymm0'
/tmp/cc8j8kGs.s:284: 错误: no such instruction: `vextractf32x8 $0x1,%zmm6,%ymm0'
/tmp/cc8j8kGs.s:287: 错误: no such instruction: `vextractf32x8 $0x1,%zmm4,%ymm0'
/tmp/cc8j8kGs.s:289: 错误: no such instruction: `vextractf32x8 $0x1,%zmm6,%ymm2'
/tmp/cc8j8kGs.s:294: 错误: no such instruction: `vextractf32x8 $0x1,%zmm7,%ymm0'
/tmp/cc8j8kGs.s:296: 错误: no such instruction: `vextractf32x8 $0x1,%zmm1,%ymm0'
/tmp/cc8j8kGs.s:303: 错误: no such instruction: `vextractf32x8 $0x1,%zmm7,%ymm6'
/tmp/cc8j8kGs.s:307: 错误: no such instruction: `vextractf32x8 $0x1,%zmm6,%ymm5'
/tmp/cc8j8kGs.s:311: 错误: no such instruction: `vextractf32x8 $0x1,%zmm6,%ymm7'
/tmp/cc8j8kGs.s:313: 错误: no such instruction: `vextractf32x8 $0x1,%zmm2,%ymm6'
/tmp/cc8j8kGs.s:316: 错误: no such instruction: `vextractf32x8 $0x1,%zmm2,%ymm5'
/tmp/cc8j8kGs.s:633: 错误: operand type mismatch for `vxorps'
/tmp/cc8j8kGs.s:1048: 错误: operand type mismatch for `vxorps'
/tmp/cc8j8kGs.s:1394: 错误: operand type mismatch for `vxorps'
make[2]: *** [modules/dnn/CMakeFiles/opencv_dnn.dir/layers/layers_common.avx512_skx.cpp.o] 错误 1
make[1]: *** [modules/dnn/CMakeFiles/opencv_dnn.dir/all] 错误 2
make: *** [all] 错误 2
有人说需要在对应的报错包的cmakeLists.txt中添加32位编译支持:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
结果是16线程编译的时候,本来在35%的地方报错,延迟到85%才报错,报错内容还是一样,单线程编译发现,还是dnn模块报错。折腾了很久还是没通过,最后,直接放弃编译dnn库和最后一个python库(依赖dnn):
我的cmake版本是3.10,故意设置成3.12,从而跳过cmake编译
if(${CMAKE_VERSION} VERSION_LESS 3.12)
message(STATUS "Module opencv_dnn_modern disabled because CMake version is less than 3.12")
ocv_module_disable(dnn_modern)
return()
endif()
e.安装
sudo make install
有空了再把那两个跳过的模块(dnn和python,它们都是opencv3.4.1本身就有的,不属于contrib)弄一下