參考資訊:
https://stackoverflow.com/questions/13709274/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("/usr/x86_64-w64-mingw32/include/opencv4") add_executable(main main.cpp) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_aruco430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_bgsegm430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_bioinspired430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_calib3d430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_ccalib430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_core430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_datasets430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_dnn430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_dnn_objdetect430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_dnn_superres430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_dpm430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_face430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_features2d430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_flann430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_fuzzy430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_gapi430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_hfs430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_highgui430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_imgcodecs430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_img_hash430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_imgproc430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_intensity_transform430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_line_descriptor430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_ml430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_objdetect430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_optflow430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_phase_unwrapping430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_photo430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_plot430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_quality430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_rapid430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_reg430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_rgbd430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_saliency430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_shape430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_stereo430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_stitching430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_structured_light430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_superres430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_surface_matching430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_text430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_tracking430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_video430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_videoio430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_videostab430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_xfeatures2d430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_ximgproc430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_xobjdetect430.dll.a) target_link_libraries(main /usr/x86_64-w64-mingw32/lib/libopencv_xphoto430.dll.a)
toolchain.cmake
SET(CMAKE_SYSTEM_NAME Windows) SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
編譯並且執行
$ cmake . -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake $ make