#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc,char** argv) {
Mat src = imread("/Users/hecj/Desktop/hecj.jpeg");
if(src.empty()){
printf("图片的不存在");
return -1;
}
namedWindow("test opencv",CV_WINDOW_AUTOSIZE);
imshow("test opencv",src);
waitKey(0);
return EXIT_SUCCESS;
}
编写CMakeLists.txt
# Define project name
project(main_project)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(main main.cpp)
# Link your application with OpenCV libraries
target_link_libraries(main ${OpenCV_LIBS})
cmake编译
cmake .
make
./main #执行 这是一个可执行文件