首先指定版本号和CPU核数

export OPENCV_VERSION=4.6.0
export NUM_JOBS=8

下载并解压

wget -O https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
unzip opencv.zip && \
cd opencv-${OPENCV_VERSION} && \
mkdir -p build && cd build

编译和安装

cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=YES -DWITH_GTK=ON -DBUILD_TFF=ON -DWITH_EIGEN=OFF  -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/opencv4.6.0 ..
sudo make install -j${NUM_JOBS}

可能存在的问题

…/…/lib/libopencv_imgcodecs.so.5.0.0: undefined reference to `TIFFReadRGBAStrip@LIBTIFF_4.0’

cmake选项中加上:BUILD_TIFF=ON

将anconda里面的libtiff的so文件移除掉了

sudo rm /home/ztyf/anconda3/lib/libtiff.so*

解决libpangoft2-1.0.so.0:对‘pango_font_get_hb_font‘未定义的引用

locate libpangoft2-1.0.so.0
选择/usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0,将其拷贝到报错的路径完全解决。

Ubuntu下编译opencv cuda版本//lib/x86_64-linux-gnu/libblkid.so.1 未定义‘uuid_unparse@UUID_1.0‘

sudo rm /home/xing/anaconda3/lib/libuuid.so.1

sudo ln -s /lib/i386-linux-gnu/libuuid.so.1 /home/xing/anaconda3/lib/libuuid.so.1

之后重新cmake;  sudo make -j8;   sudo make install;