1.使用cmake生成makefile
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/home/jiangfeng/opencv3.4.1/opencv-3.4.1/build/install -D OPENCV_EXTRA_MODULES_PATH=/home/jiangfeng/opencv3.4.1/opencv_contrib-3.4.1/modules ..
2.编译
https://blog.csdn.net/bj233/article/details/113351023
3.环境配置
1.修改profile文件,配置pkg-config命令的索引路径
open cv lib
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv3.4.1/lib/pkgconfig
export PKG_CONFIG_PATH
sudo source /etc/profile
2.添加ldconfig链接路径(此处可以自己新建一个/etc/ld.so.conf.d/opencv.conf)
opencv.conf:
/usr/local/opencv3.4.1/lib
3.环境测试
pkg-config opencv --modversion
4.源码编译测试
include <stdio.h>
include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
if(argc!= 2)
{
printf("usage:DisplayImage.out <Image_Path>
");
return -1;
}
Mat image;
image= imread(argv[1], 1);
if(!image.data)
{
printf("Noimage data
");
return -1;
}
namedWindow("DisplayImage",CV_WINDOW_AUTOSIZE);
imshow("DisplayImage",image);
waitKey(0);
return 0;
}
使用g++编译的时候使用命令:
g++ main.cpp -o main pkg-config --cflags --libs opencv
5.运行报错
https://blog.csdn.net/zseqsc_asd/article/details/82777224
5.1、需要安装 libgtk2.0-dev
sudo apt-get update
sudo apt-get install aptitude libgtk2.0-dev
测试:pkg-config --list-all |grep gtk
5.2、然后重新编译opencv
ubuntu安装编译参考博客:
https://blog.csdn.net/public669/article/details/99044895
https://blog.csdn.net/bj233/article/details/113351023
https://blog.csdn.net/qq_38204686/article/details/116656374?utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~default-17.no_search_link