diff --git a/modules/videoio/include/opencv2/videoio.hpp b/modules/videoio/include/opencv2/videoio.hpp index 33e38033c3..fea1068ad5 100644 --- a/modules/videoio/include/opencv2/videoio.hpp +++ b/modules/videoio/include/opencv2/videoio.hpp @@ -710,9 +710,12 @@ namespace internal { class VideoCapturePrivateAccessor; } 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 samples/cpp/snippets/videocapture_basic.cpp + @note - (C++) A basic sample on using the %VideoCapture interface can be found at - `OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp` + `OPENCV_SOURCE_CODE/samples/cpp/videocapture_combined.cpp` - (Python) A basic sample on using the %VideoCapture interface can be found at `OPENCV_SOURCE_CODE/samples/python/video.py` - (Python) A multi threaded video processing sample can be found at @@ -979,8 +982,8 @@ class IVideoWriter; Check @ref tutorial_video_write "the corresponding tutorial" for more details */ -/** @example samples/cpp/videowriter_basic.cpp -An example using VideoWriter class +/** @example samples/cpp/videowriter.cpp +An example using VideoCapture and VideoWriter class */ /** @brief Video writer class. diff --git a/samples/cpp/videocapture_basic.cpp b/samples/cpp/snippets/videocapture_basic.cpp similarity index 100% rename from samples/cpp/videocapture_basic.cpp rename to samples/cpp/snippets/videocapture_basic.cpp diff --git a/samples/cpp/videocapture_camera.cpp b/samples/cpp/videocapture_camera.cpp deleted file mode 100644 index ca39b2093b..0000000000 --- a/samples/cpp/videocapture_camera.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include // cv::Canny() -#include - -using namespace cv; -using std::cout; using std::cerr; using std::endl; - -int main(int, char**) -{ - Mat frame; - cout << "Opening camera..." << endl; - VideoCapture capture(0); // open the first camera - if (!capture.isOpened()) - { - cerr << "ERROR: Can't initialize camera capture" << endl; - return 1; - } - - cout << "Frame width: " << capture.get(CAP_PROP_FRAME_WIDTH) << endl; - cout << " height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << endl; - cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << endl; - - cout << endl << "Press 'ESC' to quit, 'space' to toggle frame processing" << endl; - cout << endl << "Start grabbing..." << endl; - - size_t nFrames = 0; - bool enableProcessing = false; - int64 t0 = cv::getTickCount(); - int64 processingTime = 0; - for (;;) - { - capture >> frame; // read the next frame from camera - if (frame.empty()) - { - cerr << "ERROR: Can't grab camera frame." << endl; - break; - } - nFrames++; - if (nFrames % 10 == 0) - { - const int N = 10; - int64 t1 = cv::getTickCount(); - cout << "Frames captured: " << cv::format("%5lld", (long long int)nFrames) - << " Average FPS: " << cv::format("%9.1f", (double)getTickFrequency() * N / (t1 - t0)) - << " Average time per frame: " << cv::format("%9.2f ms", (double)(t1 - t0) * 1000.0f / (N * getTickFrequency())) - << " Average processing time: " << cv::format("%9.2f ms", (double)(processingTime) * 1000.0f / (N * getTickFrequency())) - << std::endl; - t0 = t1; - processingTime = 0; - } - if (!enableProcessing) - { - imshow("Frame", frame); - } - else - { - int64 tp0 = cv::getTickCount(); - Mat processed; - cv::Canny(frame, processed, 400, 1000, 5); - processingTime += cv::getTickCount() - tp0; - imshow("Frame", processed); - } - int key = waitKey(1); - if (key == 27/*ESC*/) - break; - if (key == 32/*SPACE*/) - { - enableProcessing = !enableProcessing; - cout << "Enable frame processing ('space' key): " << enableProcessing << endl; - } - } - std::cout << "Number of captured frames: " << nFrames << endl; - return nFrames > 0 ? 0 : 1; -} diff --git a/samples/cpp/videocapture_combined.cpp b/samples/cpp/videocapture_combined.cpp new file mode 100644 index 0000000000..9ccc7cfb5a --- /dev/null +++ b/samples/cpp/videocapture_combined.cpp @@ -0,0 +1,88 @@ +/* + * This sample demonstrates how to read and display frames from a video file, a camera device or an image sequence. + * The sample also demonstrates extracting audio buffers from a video file. + + * Capturing video and audio simultaneously from camera device is not supported by OpenCV. +*/ + + +#include +#include +#include +#include + +using namespace cv; +using namespace std; + +string keys = +"{input i | 0 | Path to input image or video file. Skip this argument to capture frames from a camera.}" +"{help h | | print usage}"; + +int main(int argc, char** argv) +{ + CommandLineParser parser(argc, argv, keys); + + parser.about("This sample demonstrates how to read and display frames from a video file, a camera device or an image sequence \n" + "Usage:\n --input/-i=