CMakeLists.txt编写

最简单的形式如下:

  1. # cmake needs this line
  2. cmake_minimum_required(VERSION 2.8)
  3. # define project name
  4. project(opencvTest)
  5. # fined OpenCV
  6. find_package(OpenCV REQUIRED)
  7. # display message
  8. message(STATUS "OpenCV library status:")
  9. message(STATUS " version: ${OpenCV_VERSION}")
  10. message(STATUS " libraries: ${OpenCV_LIBS}")
  11. message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
  12. # Add OpenCV headers location to your include paths
  13. include_directories(${OpenCV_INCLUDE_DIRS})
  14. # Declare the executable target built from your sources
  15. set(SRC_LIST main.cpp)
  16. add_executable(main ${SRC_LIST})
  17. # Link your application with OpenCV libraries
  18. target_link_libraries(main ${OpenCV_LIBS})

头文件包括

  1. #include<opencv2/opencv.hpp>
  2. #include<opencv2/highgui.hpp>
  3. #include <opencv2/highgui/highgui_c.h>
  4. using namespace cv;
  5. // etc

Mat矩阵处理

Mat类,参考博客:链接

图像处理

函数:有 python-opencv 一样的形式
imread(path)
imshow(str:winname, image)
waitKey(n_ms)
imwrite(path, image)

视频处理

读取视频:

  1. VideoCapture capture;
  2. capture.open("./video/MaBaoguo.avi");
  3. // frame << capture; // 当作流处理
  4. // capture.read(frame);
  5. // ...
  6. capture.release()

保存视频:

  1. int myFourCC = VideoWriter::fourcc('X', 'V', 'I', 'D'); // .avi
  2. VideoWriter outputVideo("MaBaoguoFiltered.avi", myFourCC, rate, size, true);
  3. // outputVideo << frame; 帧写入
  4. // ...
  5. outputVideo.release()