一、安装依赖
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
二、下载安装包和依赖包
1.下载opencv包
https://codeload.github.com/opencv/opencv/zip/4.5.1
unzip opencv-4.5.1.zip
2.下载opencv_contrib-4.5.1.tar.gz
https://codeload.github.com/opencv/opencv_contrib/tar.gz/4.5.1
tar -zxvf opencv_contrib-4.5.1.tar.gz
3.下载ippicv
修改opencv-4.5.1/3rdparty/ipicv/ippicv.cmake
set(THE_ROOT "${OpenCV_BINARY_DIR}/3rdparty/ippicv")
ocv_download(FILENAME ${OPENCV_ICV_NAME}
HASH ${OPENCV_ICV_HASH}
URL
"${OPENCV_IPPICV_URL}"
"$ENV{OPENCV_IPPICV_URL}"
"/home/mzgong/work/opencv/" #修改为ippicv_2020_lnx_intel64_20191018_general.tgz所在的路径
DESTINATION_DIR "${THE_ROOT}"
ID IPPICV
STATUS res
UNPACK RELATIVE_URL)
4.下载face_landmark_model.dat
拷贝到opencv-4.5.1/samples/dnn/face_detector/路径下
5.下载patch__.zip
https://github.com/opencv/opencv_contrib/files/4520852/patch__.zip
cd opencv-4.5.1/.cache/xfeatures2d/
unzip patch__.zip
三、编译
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D WITH_TBB=ON -D WITH_V4L=ON
-D WITH_QT=ON -D WITH_GTK=ON
-D WITH_OPENGL=ON -D WITH_VTK=ON
-D OPENCV_GENERATE_PKGCONFIG=YES
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D OPENCV_GENERATE_PKGCONFIG=ON
-D OPENCV_ENABLE_NONFREE=ON
-D OPENCV_EXTRA_MODULES_PATH=/home/mzgong/work/opencv/opencv_contrib-4.5.1/modules #opencv_contriib-4.5.1所在路径
-D BUILD_EXAMPLES=ON -D BUILD_TESTS=OFF ..
make -j8
sudo make install
问题1:
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::InitVLOG3__(int**, int*, char const*, int)'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::kLogSiteUninitialized'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::LogMessage::stream()'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::LogMessage::LogMessage(char const*, int)'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::LogMessage::~LogMessage()'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `fLI::FLAGS_v'
../../lib/libopencv_sfm.so.4.5.1: undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
关闭BUILD中的TEST项,即-DBUILD_TESTS=OFF可通过。
/usr/local/lib/libopencv_imgcodecs.so: undefined reference to TIFFReadDirectory@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so: undefined reference toTIFFWriteEncodedStrip@LIBTIFF_4.0’
/usr/local/lib/libopencv_imgcodecs.so: undefined reference to TIFFIsTiled@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so: undefined reference toTIFFOpen@LIBTIFF_4.0’
/usr/local/lib/libopencv_imgcodecs.so: undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so: undefined reference toTIFFSetField@LIBTIFF_4.0’
/usr/local/lib/libopencv_imgcodecs.so: undefined reference to TIFFWriteScanline@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so: undefined reference toTIFFGetField@LIBTIFF_4.0’
/usr/local/lib/libopencv_imgcodecs.so: undefined reference to TIFFScanlineSize@LIBTIFF_4.0'
/usr/local/lib/libopencv_imgcodecs.so: undefined reference toTIFFNumberOfStrips@LIBTIFF_4.0’
关闭环境变量中的anaconda。sudo apt install libtiff-dev