OpenCV
3.2.0
Open Source Computer Vision
|
Class for video capturing from video files, image sequences or cameras. More...
#include "videoio.hpp"
Public Member Functions | |
VideoCapture () | |
Default constructor. More... | |
VideoCapture (const String &filename) | |
Open video file or a capturing device or a IP video stream for video capturing. More... | |
VideoCapture (const String &filename, int apiPreference) | |
Open video file or a capturing device or a IP video stream for video capturing with API Preference. More... | |
VideoCapture (int index) | |
Open a camera for video capturing. More... | |
virtual | ~VideoCapture () |
Default destructor. More... | |
virtual double | get (int propId) const |
Returns the specified VideoCapture property. More... | |
virtual bool | grab () |
Grabs the next frame from video file or capturing device. More... | |
virtual bool | isOpened () const |
Returns true if video capturing has been initialized already. More... | |
virtual bool | open (const String &filename) |
Open video file or a capturing device or a IP video stream for video capturing. More... | |
virtual bool | open (int index) |
Open a camera for video capturing. More... | |
bool | open (int cameraNum, int apiPreference) |
Open a camera for video capturing. More... | |
virtual bool | open (const String &filename, int apiPreference) |
Open video file or a capturing device or a IP video stream for video capturing with API Preference. More... | |
virtual VideoCapture & | operator>> (Mat &image) |
Stream operator to read the next video frame. More... | |
virtual VideoCapture & | operator>> (UMat &image) |
virtual bool | read (OutputArray image) |
Grabs, decodes and returns the next video frame. More... | |
virtual void | release () |
Closes video file or capturing device. More... | |
virtual bool | retrieve (OutputArray image, int flag=0) |
Decodes and returns the grabbed video frame. More... | |
virtual bool | set (int propId, double value) |
Sets a property in the VideoCapture. More... | |
Protected Attributes | |
Ptr< CvCapture > | cap |
Ptr< IVideoCapture > | icap |
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:
CvCapture
is used instead of VideoCapture. OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.cpp
OPENCV_SOURCE_CODE/samples/python/video.py
OPENCV_SOURCE_CODE/samples/python/video_threaded.py
OPENCV_SOURCE_CODE/samples/python/video_v4l2.py
cv::VideoCapture::VideoCapture | ( | ) |
Default constructor.
cv::VideoCapture::VideoCapture | ( | const String & | filename | ) |
Open video file or a capturing device or a IP video stream for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Same as VideoCapture(const String& filename, int apiPreference) but using default Capture API backends
cv::VideoCapture::VideoCapture | ( | const String & | filename, |
int | apiPreference | ||
) |
Open video file or a capturing device or a IP video stream for video capturing with API Preference.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
filename | it can be:
|
apiPreference | preferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. |
cv::VideoCapture::VideoCapture | ( | int | index | ) |
Open a camera for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
index | camera_id + domain_offset (CAP_*) id of the video capturing device to open. To open default camera using default backend just pass 0. Use a domain_offset to enforce a specific reader implementation if multiple are available like cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. e.g. to open Camera 1 using the MS Media Foundation API use index = 1 + cv::CAP_MSMF |
|
virtual |
Default destructor.
The method first calls VideoCapture::release to close the already opened file or camera.
|
virtual |
Returns the specified VideoCapture property.
propId | Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from Additional flags for video I/O API backends |
|
virtual |
Grabs the next frame from video file or capturing device.
true
(non-zero) in the case of success.The method/function grabs the next frame from video file or camera and returns true (non-zero) in the case of success.
The primary use of the function is in multi-camera environments, especially when the cameras do not have hardware synchronization. That is, you call VideoCapture::grab() for each camera and after that call the slower method VideoCapture::retrieve() to decode and get frame from each camera. This way the overhead on demosaicing or motion jpeg decompression etc. is eliminated and the retrieved frames from different cameras will be closer in time.
Also, when a connected camera is multi-head (for example, a stereo camera or a Kinect device), the correct way of retrieving data from it is to call VideoCapture::grab() first and then call VideoCapture::retrieve() one or more times with different values of the channel parameter.
|
virtual |
Returns true if video capturing has been initialized already.
If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.
|
virtual |
Open video file or a capturing device or a IP video stream for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters are same as the constructor VideoCapture(const String& filename)
true
if the file has been successfully openedThe method first calls VideoCapture::release to close the already opened file or camera.
|
virtual |
Open a camera for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters are same as the constructor VideoCapture(int index)
true
if the camera has been successfully opened.The method first calls VideoCapture::release to close the already opened file or camera.
bool cv::VideoCapture::open | ( | int | cameraNum, |
int | apiPreference | ||
) |
Open a camera for video capturing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Parameters are similar as the constructor VideoCapture(int index),except it takes an additional argument apiPreference.
|
virtual |
Open video file or a capturing device or a IP video stream for video capturing with API Preference.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference)
true
if the file has been successfully openedThe method first calls VideoCapture::release to close the already opened file or camera.
|
virtual |
Stream operator to read the next video frame.
|
virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
virtual |
Grabs, decodes and returns the next video frame.
[out] | image | the video frame is returned here. If no frames has been grabbed the image will be empty. |
false
if no frames has been grabbedThe method/function combines VideoCapture::grab() and VideoCapture::retrieve() in one call. This is the most convenient method for reading video files or capturing data from decode and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns empty image (with cv::Mat, test it with Mat::empty()).
|
virtual |
Closes video file or capturing device.
The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor.
The C function also deallocates memory and clears *capture pointer.
|
virtual |
Decodes and returns the grabbed video frame.
[out] | image | the video frame is returned here. If no frames has been grabbed the image will be empty. |
flag | it could be a frame index or a driver specific flag |
false
if no frames has been grabbedThe method decodes and returns the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the method returns false and the function returns an empty image (with cv::Mat, test it with Mat::empty()).
|
virtual |
Sets a property in the VideoCapture.
propId | Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from Additional flags for video I/O API backends |
value | Value of the property. |
true
if the property is supported by backend used by the VideoCapture instance. true
this doesn't ensure that the property value has been accepted by the capture device. See note in VideoCapture::get()
|
protected |