OpenCV453
公開メンバ関数 | 静的公開メンバ関数 | 限定公開変数類 | フレンド | 全メンバ一覧
cv::VideoCapture クラス

Class for video capturing from video files, image sequences or cameras. [詳解]

#include <videoio.hpp>

公開メンバ関数

CV_WRAP VideoCapture ()
 Default constructor [詳解]
 
CV_WRAP VideoCapture (const String &filename, int apiPreference=CAP_ANY)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference [詳解]
 
CV_WRAP VideoCapture (const String &filename, int apiPreference, const std::vector< int > &params)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters [詳解]
 
CV_WRAP VideoCapture (int index, int apiPreference=CAP_ANY)
 Opens a camera for video capturing [詳解]
 
CV_WRAP VideoCapture (int index, int apiPreference, const std::vector< int > &params)
 Opens a camera for video capturing with API Preference and parameters [詳解]
 
virtual ~VideoCapture ()
 Default destructor [詳解]
 
virtual CV_WRAP bool open (const String &filename, int apiPreference=CAP_ANY)
 Opens a video file or a capturing device or an IP video stream for video capturing. [詳解]
 
virtual CV_WRAP bool open (const String &filename, int apiPreference, const std::vector< int > &params)
 Opens a camera for video capturing [詳解]
 
virtual CV_WRAP bool open (int index, int apiPreference=CAP_ANY)
 Opens a camera for video capturing [詳解]
 
virtual CV_WRAP bool open (int index, int apiPreference, const std::vector< int > &params)
 Returns true if video capturing has been initialized already. [詳解]
 
virtual CV_WRAP bool isOpened () const
 Returns true if video capturing has been initialized already. [詳解]
 
virtual CV_WRAP void release ()
 Closes video file or capturing device. [詳解]
 
virtual CV_WRAP bool grab ()
 Grabs the next frame from video file or capturing device. [詳解]
 
virtual CV_WRAP bool retrieve (OutputArray image, int flag=0)
 Decodes and returns the grabbed video frame. [詳解]
 
virtual VideoCaptureoperator>> (CV_OUT Mat &image)
 Stream operator to read the next video frame. [詳解]
 
virtual VideoCaptureoperator>> (CV_OUT UMat &image)
 
virtual CV_WRAP bool read (OutputArray image)
 Grabs, decodes and returns the next video frame. [詳解]
 
virtual CV_WRAP bool set (int propId, double value)
 Sets a property in the VideoCapture. [詳解]
 
virtual CV_WRAP double get (int propId) const
 Returns the specified VideoCapture property [詳解]
 
CV_WRAP String getBackendName () const
 Returns used backend API name [詳解]
 
CV_WRAP void setExceptionMode (bool enable)
 
CV_WRAP bool getExceptionMode ()
 query if exception mode is active
 

静的公開メンバ関数

static bool waitAny (const std::vector< VideoCapture > &streams, CV_OUT std::vector< int > &readyIndex, int64 timeoutNs=0)
 Wait for ready frames from VideoCapture. [詳解]
 

限定公開変数類

Ptr< CvCapturecap
 
Ptr< IVideoCapture > icap
 
bool throwOnFail
 

フレンド

class internal::VideoCapturePrivateAccessor
 

詳解

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:

覚え書き
In C API the black-box structure CvCapture is used instead of VideoCapture.
  • (C++) A basic sample on using the VideoCapture interface can be found at OPENCV_SOURCE_CODE/samples/cpp/videocapture_starter.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 OPENCV_SOURCE_CODE/samples/python/video_threaded.py
  • (Python) VideoCapture sample showcasing some features of the Video4Linux2 backend OPENCV_SOURCE_CODE/samples/python/video_v4l2.py

構築子と解体子

◆ VideoCapture() [1/5]

CV_WRAP cv::VideoCapture::VideoCapture ( )

Default constructor

覚え書き
In C API, when you finished working with video, release CvCapture structure with cvReleaseCapture(), or use Ptr<CvCapture> that calls cvReleaseCapture() automatically in the destructor.

◆ VideoCapture() [2/5]

CV_WRAP cv::VideoCapture::VideoCapture ( const String &  filename,
int  apiPreference = CAP_ANY 
)
explicit

Opens a video file or a capturing device or an IP video stream for video capturing with API Preference

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

引数
filenameit can be:
  • name of video file (eg. video.avi)
  • or image sequence (eg. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  • or URL of video stream (eg. protocol://host:port/script_name?script_params|auth)
  • or GStreamer pipeline string in gst-launch tool format in case if GStreamer is used as backend Note that each video stream or IP camera feed has its own URL scheme. Please refer to the documentation of source stream to know the right URL.
apiPreferencepreferred 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::VideoCaptureAPIs

◆ VideoCapture() [3/5]

CV_WRAP cv::VideoCapture::VideoCapture ( const String &  filename,
int  apiPreference,
const std::vector< int > &  params 
)
explicit

Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

◆ VideoCapture() [4/5]

CV_WRAP cv::VideoCapture::VideoCapture ( int  index,
int  apiPreference = CAP_ANY 
)
explicit

Opens a camera for video capturing

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

引数
indexid of the video capturing device to open. To open default camera using default backend just pass 0. (to backward compatibility usage of camera_id + domain_offset (CAP_*) is valid when apiPreference is CAP_ANY)
apiPreferencepreferred Capture API backends to use. Can be used to enforce a specific reader implementation if multiple are available: e.g. cv::CAP_DSHOW or cv::CAP_MSMF or cv::CAP_V4L.
参照
cv::VideoCaptureAPIs

◆ VideoCapture() [5/5]

CV_WRAP cv::VideoCapture::VideoCapture ( int  index,
int  apiPreference,
const std::vector< int > &  params 
)
explicit

Opens a camera for video capturing with API Preference and parameters

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

◆ ~VideoCapture()

virtual cv::VideoCapture::~VideoCapture ( )
virtual

Default destructor

The method first calls VideoCapture::release to close the already opened file or camera.

関数詳解

◆ get()

virtual CV_WRAP double cv::VideoCapture::get ( int  propId) const
virtual

Returns the specified VideoCapture property

引数
propIdProperty 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 for the specified property. Value 0 is returned when querying a property that is not supported by the backend used by the VideoCapture instance.
覚え書き
Reading / writing properties involves many layers. Some unexpected result might happens along this chain.
VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware
CV_WRAP VideoCapture()
Default constructor
Backend
Enum of computation backends supported by layers.
Definition: dnn/dnn.hpp:66
The returned value might be different from what really used by the device or it could be encoded using device dependent rules (eg. steps or percentage). Effective behaviour depends from device driver and API Backend

◆ getBackendName()

CV_WRAP String cv::VideoCapture::getBackendName ( ) const

Returns used backend API name

覚え書き
Stream should be opened.

◆ grab()

virtual CV_WRAP bool cv::VideoCapture::grab ( )
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.

tutorial_kinect_openni

◆ isOpened()

virtual CV_WRAP bool cv::VideoCapture::isOpened ( ) const
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.

◆ open() [1/4]

virtual CV_WRAP bool cv::VideoCapture::open ( const String &  filename,
int  apiPreference,
const std::vector< int > &  params 
)
virtual

Opens a camera for video capturing

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

戻り値
true if the file has been successfully opened

The method first calls VideoCapture::release to close the already opened file or camera.

◆ open() [2/4]

virtual CV_WRAP bool cv::VideoCapture::open ( const String &  filename,
int  apiPreference = CAP_ANY 
)
virtual

Opens a video file or a capturing device or an IP video stream for video capturing.

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)

戻り値
true if the file has been successfully opened

The method first calls VideoCapture::release to close the already opened file or camera.

◆ open() [3/4]

virtual CV_WRAP bool cv::VideoCapture::open ( int  index,
int  apiPreference,
const std::vector< int > &  params 
)
virtual

Returns true if video capturing has been initialized already.

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

戻り値
true if the camera has been successfully opened.

The method first calls VideoCapture::release to close the already opened file or camera.

◆ open() [4/4]

virtual CV_WRAP bool cv::VideoCapture::open ( int  index,
int  apiPreference = CAP_ANY 
)
virtual

Opens a camera for video capturing

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)

戻り値
true if the camera has been successfully opened.

The method first calls VideoCapture::release to close the already opened file or camera.

◆ operator>>() [1/2]

virtual VideoCapture & cv::VideoCapture::operator>> ( CV_OUT Mat image)
virtual

Stream operator to read the next video frame.

参照
read()

◆ operator>>() [2/2]

virtual VideoCapture & cv::VideoCapture::operator>> ( CV_OUT UMat image)
virtual

これはオーバーロードされたメンバ関数です。利便性のために用意されています。元の関数との違いは引き数のみです。

参照
read()

◆ read()

virtual CV_WRAP bool cv::VideoCapture::read ( OutputArray  image)
virtual

Grabs, decodes and returns the next video frame.

引数
[out]imagethe video frame is returned here. If no frames has been grabbed the image will be empty.
戻り値
false if no frames has been grabbed

The 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()).

覚え書き
In C API, functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.

◆ release()

virtual CV_WRAP void cv::VideoCapture::release ( )
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.

◆ retrieve()

virtual CV_WRAP bool cv::VideoCapture::retrieve ( OutputArray  image,
int  flag = 0 
)
virtual

Decodes and returns the grabbed video frame.

引数
[out]imagethe video frame is returned here. If no frames has been grabbed the image will be empty.
flagit could be a frame index or a driver specific flag
戻り値
false if no frames has been grabbed

The 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()).

参照
read()
覚え書き
In C API, functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage and then do whatever you want with the copy.

◆ set()

virtual CV_WRAP bool cv::VideoCapture::set ( int  propId,
double  value 
)
virtual

Sets a property in the VideoCapture.

引数
propIdProperty 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
valueValue of the property.
戻り値
true if the property is supported by backend used by the VideoCapture instance.
覚え書き
Even if it returns true this doesn't ensure that the property value has been accepted by the capture device. See note in VideoCapture::get()

◆ setExceptionMode()

CV_WRAP void cv::VideoCapture::setExceptionMode ( bool  enable)
inline

Switches exceptions mode

methods raise exceptions if not successful instead of returning an error code

◆ waitAny()

static bool cv::VideoCapture::waitAny ( const std::vector< VideoCapture > &  streams,
CV_OUT std::vector< int > &  readyIndex,
int64  timeoutNs = 0 
)
static

Wait for ready frames from VideoCapture.

引数
streamsinput video streams
readyIndexstream indexes with grabbed frames (ready to use .retrieve() to fetch actual frame)
timeoutNsnumber of nanoseconds (0 - infinite)
戻り値
true if streamReady is not empty
例外
ExceptionException on stream errors (check .isOpened() to filter out malformed streams) or VideoCapture type is not supported

The primary use of the function is in multi-camera environments. The method fills the ready state vector, grabs video frame, if camera is ready.

After this call use VideoCapture::retrieve() to decode and fetch frame data.


このクラス詳解は次のファイルから抽出されました: