标签:配置 cpp 添加 bdc 创建 ati doc gtk2 type
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
cd ~/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_GENERATE_PKGCONFIG=ON ..
注意: -DOPENCV_GENERATE_PKGCONFIG=ON 会生成.pc文件, 想在VSCode中使用的话一定要加。
make -j7 # 使用7个线程
sudo make install
要想在VSCode中使用OpenCV, 要将生成的.pc文件添加到环境变量。
看下是否有这个文件
接下来设置环境变量
vim /etc/bash.bashrc
添加下面两行
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
#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>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
g++ `pkg-config opencv --cflags` DisplayImage.cpp -o DisplayImage `pkg-config opencv --libs`
运行一下
./DisplayImage /home/hichens/Datasets/pic/bigbang.jpg # 图片路径
创建 CMakelists.txt文件
vim CMakelists.txt
build
mkdir build
cd build
cmake ..
make
运行一下
./DisplayImage /home/hichens/Datasets/pic/bigbang.jpg # 图片路径
标签:配置 cpp 添加 bdc 创建 ati doc gtk2 type
原文地址:https://www.cnblogs.com/hichens/p/12665897.html