首先写一个简单的测试代码
#include <opencv2/opencv.hpp> #include <iostream> #include <string> using namespace cv; using namespace std; int main() { Mat img = imread("img_test.jpg"); if(img.empty()) { cout<<"error"; return -1; } cout<<"My picture: "<< img.size() <<endl; return 0; }
之后,
写一个CMakeLists.txt 文件,try.cpp为相应的C++文件,project后面接的是想要生成的可执行文件名
cmake_minimum_required(VERSION 2.8) project(opencv) find_package(OpenCV REQUIRED) add_executable(opencv try.cpp) target_link_libraries(opencv ${OpenCV_LIBS})
写好了之后运行
cmake .
之后
make
相应路径下会生成一个名字为opencv的文件,执行
./opencv
成功得到结果~