CMakeLists.txt编写
最简单的形式如下:
# cmake needs this linecmake_minimum_required(VERSION 2.8)# define project nameproject(opencvTest)# fined OpenCVfind_package(OpenCV REQUIRED)# display messagemessage(STATUS "OpenCV library status:")message(STATUS " version: ${OpenCV_VERSION}")message(STATUS " libraries: ${OpenCV_LIBS}")message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")# Add OpenCV headers location to your include pathsinclude_directories(${OpenCV_INCLUDE_DIRS})# Declare the executable target built from your sourcesset(SRC_LIST main.cpp)add_executable(main ${SRC_LIST})# Link your application with OpenCV librariestarget_link_libraries(main ${OpenCV_LIBS})
头文件包括
#include<opencv2/opencv.hpp>#include<opencv2/highgui.hpp>#include <opencv2/highgui/highgui_c.h>using namespace cv;// etc
Mat矩阵处理
Mat类,参考博客:链接
图像处理
函数:有 python-opencv 一样的形式imread(path)imshow(str:winname, image)waitKey(n_ms)imwrite(path, image)
视频处理
读取视频:
VideoCapture capture;capture.open("./video/MaBaoguo.avi");// frame << capture; // 当作流处理// capture.read(frame);// ...capture.release()
保存视频:
int myFourCC = VideoWriter::fourcc('X', 'V', 'I', 'D'); // .aviVideoWriter outputVideo("MaBaoguoFiltered.avi", myFourCC, rate, size, true);// outputVideo << frame; 帧写入// ...outputVideo.release()
