Ubuntu 安装opencv2.4的过程

环境:Ubuntu16.04

1、安装依赖项

# 安装编译工具
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

2、下载源码

地址:https://opencv.org/releases/
我选择的是2.4.13.6版本

3、编译安装

cd /home/jinye/lib/opencv-2.4.13.6
mkdir -p release/installed
cd release
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/home/jinye/lib/opencv-2.4.13.6/release/installed \
-D WITH_CUDA=OFF \
-D BUILD_TIFF=ON \
-D ENABLE_CXX11=ON ..
make -j2
make install

这里,因为已经安装过opencv3了,所以选择安装在其他文件夹下,防止被覆盖,并且关闭cuda

4、设置环境变量(可选)

sudo gedit ~/.bashrc
export PKG_CONFIG_PATH=/home/jinye/lib/opencv-2.4.13.6/release/installed/lib/pkgconfig
export LD_LIBRARY_PATH=/home/jinye/lib/opencv-2.4.13.6/release/installed/lib

5、可能遇到的问题

/usr/bin/ld: warning: libpcre.so.1, needed by //home/jinye/anaconda3/lib/libglib-2.0.so.0, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libzstd.so.1.3.7, needed by //home/jinye/anaconda3/lib/libtiff.so.5, not found (try using -rpath or -rpath-link)
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_initCStream' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_freeCStream’
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_maxCLevel' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_createCStream’
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_isError' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_getErrorName’
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_endStream' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_createDStream’
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_initDStream' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_freeDStream’
//home/jinye/anaconda3/lib/libtiff.so.5: undefined reference to ZSTD_compressStream' //home/jinye/anaconda3/lib/libtiff.so.5: undefined reference toZSTD_decompressStream’

可以选择opencv源码的tiff库进行编译,在cmake阶段添加参数

-D BUILD_TIFF=ON

附:查看opencv版本

pkg-config --modversion opencv

参考:
https://blog.csdn.net/learning_tortosie/article/details/80594399

你可能感兴趣的:(环境与库,ubuntu,opencv)