Created
January 12, 2018 16:40
-
-
Save suzumura-ss/7cd688b1fd3fb63c3c43e5417b2216e0 to your computer and use it in GitHub Desktop.
openCV video i/o example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/opencv.hpp> | |
#include <opencv2/video.hpp> | |
#pragma comment(lib, "opencv_core320.lib") | |
#pragma comment(lib, "opencv_videoio320.lib") | |
int main(int argc, const char* argv[]) | |
{ | |
if (argc != 3) { | |
return 1; | |
} | |
cv::VideoCapture videoReader(argv[1]); | |
if (!videoReader.isOpened()) { | |
printf("open failed - %s\n", argv[1]); | |
return 1; | |
} | |
double fps = videoReader.get(cv::CAP_PROP_FPS); | |
cv::Size size((int)videoReader.get(cv::CAP_PROP_FRAME_WIDTH), (int)videoReader.get(cv::CAP_PROP_FRAME_HEIGHT)); | |
int fourcc = (int)videoReader.get(cv::CAP_PROP_FOURCC); | |
cv::VideoWriter videoWriter(argv[2], fourcc, fps, size, true); | |
if (!videoWriter.isOpened()) { | |
printf("open failed - %s\n", argv[2]); | |
return 1; | |
} | |
cv::Mat src; | |
while (videoReader.grab()) { | |
if (!videoReader.retrieve(src)) break; | |
videoWriter << src; | |
} | |
videoWriter.release(); | |
videoReader.release(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment