linux下搭建opencv 4.5开发环境及Demo

1.centos

2.官网下载源码

https://github.com/opencv/opencv/tagsicon-default.png?t=M276https://github.com/opencv/opencv/tags3.解压

unzip opencv-4.5.5.zip
cd opencv-4.5.5

4.配置

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/data1/xxx/workspace/opencv/output ..

其中,CMAKE_BUILD_TYPE指定Release或者Debug

CMAKE_INSTALL_PREFIX指定编译以后,安装的目录

.. (点点)指定opencv源码更目录

更多配置选项,参考官网:

OpenCV configuration options referenceicon-default.png?t=M276https://docs.opencv.org/4.x/db/d05/tutorial_config_reference.html

由于本机已经存在了ffmpeg的老版本,导致编译报错,不想动老版本,于是把ffmepg禁用掉

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/data1/xxx/workspace/opencv/output -D WITH_FFMPEG=OFF ..

5.编译

make
make install

6.hello opencv

cd ..
mkdir demo
cd demo
vim cvdemo.cpp
//cvdemo.cpp
#include "opencv2/opencv.hpp"

int main()
{
    printf("hello opencv!\r\n");
    return 0;
}

build:

g++ -g -Wall -std=c++11 cvdemo.cpp -o cvdemo -I../output/include/opencv4/ -L../output/lib64 -lopencv_ml -lopencv_core

执行

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data1/moon/workspace/opencv/output/lib64/
~/workspace/opencv/mixdemo$ ./cvdemo 
hello opencv!

你可能感兴趣的:(音视频开发学习,积累跬步,c++,音视频)