OpenCV >> C/C++

show mp4


參考資訊:
1. reading-video-from-file-opencv

main.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using std::string;

int main(int argc, char** argv)
{
  Mat frame;
  VideoCapture capture("main.mp4");

  if(!capture.isOpened()){
    printf("failed to load mp4");
    return -1;
  }

  namedWindow("w", 1);
  while(1){
    capture >> frame;
    if(frame.empty()){
      break;
    }
    imshow("w", frame);
    waitKey(20);
  }
  waitKey(0);
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(main)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

編譯並且執行

$ cmake .
$ make
$ ./main


返回上一頁