centos7下opencv3.4安装

配置好epel源

yum -y install epel-release

  1. yum install gcc gcc-c++  
  2. yum install cmake  
  3. yum install python-devel numpy 
opencv的依赖项

yum install ffmpeg-devel

安装opencv

  1. $cd opencv  
  2. $madir release     
  3. $cd release  
  4.   
  5. $cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..    
  6. $cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..    
  7. $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 ..    
  8. $cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  
  9.   
  10. $make  
  11.   
  12. $sudo make install

安装好后需要加动态库配置:
/bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'


然后加载动态库:

ldconfig


  1. #include   
  2. #include   
  3. #include   
  4.   
  5. int main(int argc,char *argv[])  
  6. {  
  7.     cv::Mat image;  
  8.     image=cv::imread("1.png");  
  9.       
  10.     cv::namedWindow("1.png");  
  11.     cv::imshow("1.png",image);  
  12.   
  13.     cv::waitKey();  
  14.     return 0;  
  15. }  

编译前设置pkgconfig路径:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/


然后用g++编译:

[cpp]  view plain  copy
  1. g++ -g -o test test.cpp `pkg-config --cflags --libs opencv`  


运行:

./test


你可能感兴趣的:(centos7下opencv3.4安装)