ubuntu下编译opencv

目录

1. 下载opencv和opencv-contrib

2. 安装依赖

3. cmake

4. make

5. 安装

6. 配置opencv的路径

7. 测试

 后续


1. 下载opencv和opencv-contrib

https://github.com/opencv/opencv/archive/refs/tags/4.6.0.zip

https://github.com/opencv/opencv_contrib/archive/refs/tags/4.6.0.zip

2. 安装依赖

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libgtk-3-dev libgtkglext1-dev libgstreamer1.0-dev libavresample-dev  libgphoto2-dev libopenblas-dev libatlas-base-dev doxygen libgstreamer-ocaml-dev libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamer1.0-dev libgstreamermm-1.0-dev libtesseract-dev liblept5 libleptonica-dev liblapacke-dev libgstreamer-opencv1.0-0 libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-good1.0-dev libgstreamerd-3-dev libgstreamermm-1.0-dev libv4l-dev libprotobuf-dev libhdf5-dev libgflags-dev python3-numpy

3. cmake

cd opencv-4.6.0/
mkdir release
cd release/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv460 -D OPENCV_EXTRA_MODULES_PATH=/home/zxq/code/c++/opencv_contrib-4.6.0/modules ..

结果如下。

ubuntu下编译opencv_第1张图片

 4. make

make -j 12

 结果如下。

ubuntu下编译opencv_第2张图片

5. 安装

sudo make install 

 结果如下。

 右上可知,opencv被安装在/usr/local/opencv460/

6. 配置opencv的路径

sudo gedit /etc/ld.so.conf.d/opencv.conf

添加内容:
/usr/local/opencv460/lib

再sudo一下使配置路径生效
sudo ldconfig 



7. 测试

cd到opencv测试用例目录。

cd samples
cd cpp
cd example_cmake
cmake .

结果如下。

make
./opencv_example

结果如下。

ubuntu下编译opencv_第3张图片

 ubuntu下编译opencv_第4张图片

出现这个弹窗,说明安装成功。


 后续

在ubuntu 下使用CodeBlock配置Opencv

(1)settings->compiler->global compiler settings ->compiler Flags

勾选 Target x86_64 (64bit) [-m64]

(2)global compiler settings ->Search directories->Compiler

add 包含目录。

/usr/local/opencv460/include
/usr/local/opencv460/include/opencv4
/usr/local/opencv460/include/opencv4/opencv2

(3)global compiler settings ->Search directories->Linker

add 库文件路径。

/usr/local/opencv460/lib

(4)global compiler settings ->Linker settings

add 库文件。点击add然后如下全选。

ubuntu下编译opencv_第5张图片

 新建工程:File->New->Projects->Opencv project

ubuntu下编译opencv_第6张图片

你可能感兴趣的:(OpenCV,环境搭建,opencv,ubuntu,计算机视觉)