说明
以下是opencv的demo程序需要配置的CmakeList.txt内容和main.cpp的内容
可以直接使用cmake编译,也可以通过clion使用cmake编译
visit: http://blog.csdn.net/gxuan/article/details/7701035
CmakeList.txt
cmake_minimum_required(VERSION 3.6)
project(opencv_adaboost) # project name
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# define variables
# set(var value)
set(SOURCE_FILES main.cpp)
set(OPENCV "/home/hui/ide/opencv/opencv-2.4.13/x64_bin") # 引号应该可以使得空格取消分割的作用
# opencv的所有lib
set(OPENCV_LIB opencv_calib3d opencv_contrib opencv_core opencv_features2d opencv_flann opencv_gpu opencv_highgui
opencv_imgproc opencv_legacy opencv_ml opencv_nonfree opencv_objdetect opencv_ocl opencv_photo opencv_stitching
opencv_superres opencv_ts opencv_video opencv_videostab rt pthread m dl)
# include_direcctory 和 link_directorys 必须在定义相关的target(add_executable or add_library)之前
# target不会到在他后面定义的directory中寻找.h文件和.lib文件,因此错序可能会报错
# 指定搜索.h file的目录
include_directories(${OPENCV}/include ${OPENCV}/include/opencv) # include directory for all targets
# target_include_directories(target dir1 dir2 ...) # include directory for specified target
# 指定搜索.lib file的目录
link_directories(${OPENCV}/lib) # libraray search path
# link_libarrays(lib1, lib2...) # link library to all targets
# 指定从哪些源代码文件中生成exe或lib
# add_library(target source1, source2...) # compiler sources to a library named target, not a exe
add_executable(opencv_adaboost ${SOURCE_FILES}) # compiler sources to a exe named target, not a library
target_link_libraries(opencv_adaboost ${OPENCV_LIB}) # link library to specified target. must after define target opencv_adaboost
main.cpp
#include <cv.h>
#include <highgui.h>
using namespace std;
int main()
{
IplImage * test;
test = cvLoadImage("D:\\Sample_8.bmp");//图片路径
cvNamedWindow("test_demo", 1);
cvShowImage("test_demo", test);
cvWaitKey(0);
cvDestroyWindow("test_demo");
cvReleaseImage(&test);
return 0;
}