总结:CentOS 安装opencv4.1.0的详细安装步骤

安装 额外工具

  1. yum install gcc gcc-c++

  2. yum install cmake3

  3. yum install gtk2-devel

  4. yum install ant

 

安装opencv

下载: 官方地址:https://opencv.org/releases/

(本地scp到服务器

scp .\opencv-4.1.0.zip [email protected]:/home/

 

(以下 9 ~ 12步 为本人针对之前生产环境及CMakeLists配置,因人而异不用一致)

 

 

 

  1. cd /home

  2. unzip opencv-4.1.0.zip

  3. cd opencv-4.1.0

  4. mkdir build

  5. cd build

  6. cmake3 -D BUILD_SHARED_LIBS=ON -D BUILD_TESTS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv/ ..

  7. make

  8. make install

  9. cd /usr/local/opencv

  10. cp -r include /usr/local/

  11. cd /usr/local/opencv/lib64

  12. cp libopencv* /usr/local/lib64 

  13. vim /etc/ld.so.conf      (增加: /usr/local/lib64    /usr/local/lib )    

  14. source /etc/profile

 

测试 opencv

 

 

 

cd /home

(传一张图像到服务器  scp .\1.png [email protected]:/home/)

 

vim testOpenCV.cpp

#代码如下

#include

#include

int main(){

    std::cout << “ h w ” << std::endl;

    cv::Mat img = cv::imread(“/home/1.png”);

    cv::imwrite(“/home/11.png”, img);

    return 0;

}

 

g++ testOpenCV.cpp -I /usr/local/include/opencv4 -L /usr/local/lib64 -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_calib3d -lopencv_features2d -liconv -std=gnu++11

 

./a.out

 

打完收工!

你可能感兴趣的:(C/C++,OpenCV)