Eclipse CDT 使用OpenCV


代码

#include  
#include   
#include   
  
  
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
Eclipse CDT 使用OpenCV_第1张图片
  • 配置openCv位置
  1. GCC C++ Compiler->Includes->Include paths(-l)
    添加opencv位置:终端输入pkg-config --cflags opencv
    我的是-I/usr/include/opencv,那么位置是“/usr/include/opencv”。
  2. 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

  1. GCC C++ Linker->Libraries(-l)
    输入lib,需要什么就输入什么。可以全都包括进来,一劳永逸。输入格式是:opencv_core,就是相应lib后面的去掉-l

运行

先要Project->Build All !!!!!。之后运行。

你可能感兴趣的:(Eclipse CDT 使用OpenCV)