代码
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
// 读入一张图片(游戏原画)
Mat img=imread("pic.jpg");
// 创建一个名为 "游戏原画"窗口
namedWindow("游戏原画");
// 在窗口中显示游戏原画
imshow("游戏原画",img);
// 等待6000 ms后窗口自动关闭
waitKey(6000);
}
配置
参考,看第8条即可
- Project–>Properties->C/C++ Build->Settings->Tool Settings
- 配置openCv位置
-
GCC C++ Compiler->Includes->Include paths(-l)
添加opencv位置:终端输入pkg-config --cflags opencv
我的是-I/usr/include/opencv
,那么位置是“/usr/include/opencv”。 -
GCC C++ Linker->Library search path (-L)
添加lib
的位置:终端输入:pkg-config --libs opencv
。我的结果是
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d
/usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib
/usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core
/usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d
/usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann
/usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui
/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc
/usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy
/usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml
/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect
/usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl
/usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo
/usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching
/usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres
/usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts
/usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video
/usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab
那么,lib
位置是/usr/lib/x86_64-linux-gnu
。
-
GCC C++ Linker->Libraries(-l)
输入lib
,需要什么就输入什么。可以全都包括进来,一劳永逸。输入格式是:opencv_core
,就是相应lib
后面的去掉-l
。
运行
先要Project->Build All !!!!!。之后运行。