From b141762070ab6e0a8d75ecd5d6e1d809beff2fd2 Mon Sep 17 00:00:00 2001 From: Kevin Hughes Date: Mon, 15 Apr 2013 13:21:20 -0400 Subject: [PATCH 1/5] added an example of using cv::VideoCapture to read image sequences like 000.pmg, 001.png ... 100.png etc. --- samples/cpp/starter_image_sequence.cpp | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 samples/cpp/starter_image_sequence.cpp diff --git a/samples/cpp/starter_image_sequence.cpp b/samples/cpp/starter_image_sequence.cpp new file mode 100755 index 0000000000..f4b17c42a0 --- /dev/null +++ b/samples/cpp/starter_image_sequence.cpp @@ -0,0 +1,69 @@ +/* +* starter_image_sequence.cpp +* +* Created on: July 23, 2012 +* Author: Kevin Hughes +* +* A simple example of how to use the built in functionality of cv::VideoCapture to handle +* sequences of images. Image sequences are a common way to distribute data sets for various +* computer vision problems, for example the change detection data set from CVPR 2012 +* http://www.changedetection.net/ +* +*/ + +#include +#include + +#include + +using namespace cv; +using namespace std; + +void help(char** argv) +{ + cout << "\nThis program gets you started reading a sequence of images using cv::VideoCapture.\n" + << "Image sequences are a common way to distribute video data sets for computer vision.\n" + << "Usage: " << argv[0] << " \n" + << "example: " << argv[0] << " right%%02d.jpg\n" + << "q,Q,esc -- quit\n" + << "\tThis is a starter sample, to get you up and going in a copy pasta fashion\n" + << endl; +} + +int main(int argc, char** argv) +{ + if(argc != 2) + { + help(argv); + return 1; + } + + string arg = argv[1]; + VideoCapture sequence(arg); + if (!sequence.isOpened()) + { + cerr << "Failed to open Image Sequence!\n" << endl; + return 1; + } + + Mat image; + namedWindow("Image | q or esc to quit", CV_WINDOW_NORMAL); + + for(;;) + { + sequence >> image; + if(image.empty()) + { + cout << "End of Sequence" << endl; + break; + } + + imshow("image | q or esc to quit", image); + + char key = (char)waitKey(500); + if(key == 'q' || key == 'Q' || key == 27) + break; + } + + return 0; +} From eedb6fa3c48b8844ec773a28e803c90c78a8344c Mon Sep 17 00:00:00 2001 From: Kevin Hughes Date: Wed, 17 Apr 2013 13:20:32 -0400 Subject: [PATCH 2/5] removed separate example for reading image sequences and modified starter_video.cpp to better explain the functionality of VideoCapture. I also added a bit more explanation in the documentation of the VideoCapture interface --- .../reading_and_writing_images_and_video.rst | 8 +- samples/cpp/starter_video.cpp | 76 ++++++++++--------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/modules/highgui/doc/reading_and_writing_images_and_video.rst b/modules/highgui/doc/reading_and_writing_images_and_video.rst index 914856dc3a..622440a7cc 100644 --- a/modules/highgui/doc/reading_and_writing_images_and_video.rst +++ b/modules/highgui/doc/reading_and_writing_images_and_video.rst @@ -197,8 +197,8 @@ VideoCapture ------------ .. ocv:class:: VideoCapture -Class for video capturing from video files or cameras. -The class provides C++ API for capturing video from cameras or for reading video files. Here is how the class can be used: :: +Class for video capturing from video files, image sequences or cameras. +The class provides C++ API for capturing video from cameras or for reading video files and image sequences. Here is how the class can be used: :: #include "opencv2/opencv.hpp" @@ -249,7 +249,7 @@ VideoCapture constructors. .. ocv:cfunction:: CvCapture* cvCaptureFromFile( const char* filename ) .. ocv:pyoldfunction:: cv.CaptureFromFile(filename) -> CvCapture - :param filename: name of the opened video file + :param filename: name of the opened video file (eg. video.avi) or image sequence (eg. img%02d.jpg) :param device: id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0. @@ -266,7 +266,7 @@ Open video file or a capturing device for video capturing .. ocv:pyfunction:: cv2.VideoCapture.open(filename) -> retval .. ocv:pyfunction:: cv2.VideoCapture.open(device) -> retval - :param filename: name of the opened video file + :param filename: name of the opened video file (eg. video.avi) or image sequence (eg. img%02d.jpg) :param device: id of the opened video capturing device (i.e. a camera index). diff --git a/samples/cpp/starter_video.cpp b/samples/cpp/starter_video.cpp index 5bceb552cd..6a34c84d2b 100644 --- a/samples/cpp/starter_video.cpp +++ b/samples/cpp/starter_video.cpp @@ -4,47 +4,51 @@ * Created on: Nov 23, 2010 * Author: Ethan Rublee * -* A starter sample for using opencv, get a video stream and display the images +* Modified on: April 17, 2013 +* Author: Kevin Hughes +* +* A starter sample for using OpenCV VideoCapture with capture devices, video files or image sequences * easy as CV_PI right? */ -#include "opencv2/highgui/highgui.hpp" + +#include + #include -#include #include using namespace cv; using namespace std; +void help(char** av) { + cout << "The program captures frames from a video file, image sequence (01.jpg, 02.jpg ... 10.jpg) or camera connected to your computer." << endl + << "Usage:\n" << av[0] << "