1. 配置好epel源
yum -y install epel-release
yum install gcc gcc-c++
yum install cmake
yum install python-devel numpy
yum -y install vim mlocate
2. 源码编译安装
tar xf OpenCV3.4.9.tar.gz
cd opencv-opencv-f990054
mkdir build
cd build
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF .. cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
3. opencv配置与加载动态库
cd /etc/ld.so.conf.d
# 添加opencv编译产生的lib库路径到opencv.conf中
/bin/bash -c 'echo "/usr/local/lib64" > /etc/ld.so.conf.d/opencv.conf'
加载 ldconfig
ldconfig
添加PATH
vim /etc/bashrc
在文件末尾另起行加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig
export PKG_CONFIG_PATH
保存,退出后重新加载配置文件
source /etc/bashrc
更新数据库
updatedb
pkg-config配置
默认的pkg搜索链接路径/usr/lib/pkgconfig,需要将opencv.pc拷贝到pkg的默认路径下
mkdir /usr/lib/pkgconfig
cp /usr/local/lib64/pkgconfig/opencv.pc /usr/lib/pkgconfig/
4.opencv测试
cd opencv/samples/cpp/example_cmake
make
./opencv_example
有界面的话会有弹框,我这无界面会有如下提示
Built with OpenCV 3.4.9
[ WARN:0] VIDEOIO(V4L2:/dev/video0): can't open camera by index
No capture