OpenCV for Unity  2.6.0
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/4.9.0/index.html ) for the details of the argument of the method.
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
OpenCVForUnity.VideoioModule.VideoCapture Class Reference

Class for video capturing from video files, image sequences or cameras. More...

Inheritance diagram for OpenCVForUnity.VideoioModule.VideoCapture:
OpenCVForUnity.DisposableOpenCVObject OpenCVForUnity.DisposableObject

Public Member Functions

IntPtr getNativeObjAddr ()
 
 VideoCapture ()
 Default constructor. More...
 
 VideoCapture (string filename, int apiPreference)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference. More...
 
 VideoCapture (string filename)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference. More...
 
 VideoCapture (string filename, int apiPreference, MatOfInt _params)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters. More...
 
 VideoCapture (int index, int apiPreference)
 Opens a camera for video capturing. More...
 
 VideoCapture (int index)
 Opens a camera for video capturing. More...
 
 VideoCapture (int index, int apiPreference, MatOfInt _params)
 Opens a camera for video capturing with API Preference and parameters. More...
 
bool open (string filename, int apiPreference)
 Opens a video file or a capturing device or an IP video stream for video capturing. More...
 
bool open (string filename)
 Opens a video file or a capturing device or an IP video stream for video capturing. More...
 
bool open (string filename, int apiPreference, MatOfInt _params)
 Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters. More...
 
bool open (int index, int apiPreference)
 Opens a camera for video capturing. More...
 
bool open (int index)
 Opens a camera for video capturing. More...
 
bool open (int index, int apiPreference, MatOfInt _params)
 Opens a camera for video capturing with API Preference and parameters. More...
 
bool isOpened ()
 Returns true if video capturing has been initialized already. More...
 
void release ()
 Closes video file or capturing device. More...
 
bool grab ()
 Grabs the next frame from video file or capturing device. More...
 
bool retrieve (Mat image, int flag)
 Decodes and returns the grabbed video frame. More...
 
bool retrieve (Mat image)
 Decodes and returns the grabbed video frame. More...
 
bool read (Mat image)
 Grabs, decodes and returns the next video frame. More...
 
bool set (int propId, double value)
 Sets a property in the VideoCapture. More...
 
double get (int propId)
 Returns the specified VideoCapture property. More...
 
string getBackendName ()
 Returns used backend API name. More...
 
void setExceptionMode (bool enable)
 
bool getExceptionMode ()
 
- Public Member Functions inherited from OpenCVForUnity.DisposableObject
void Dispose ()
 
void ThrowIfDisposed ()
 

Static Public Member Functions

static VideoCapture __fromPtr__ (IntPtr addr)
 
- Static Public Member Functions inherited from OpenCVForUnity.DisposableObject
static IntPtr ThrowIfNullIntPtr (IntPtr ptr)
 

Protected Member Functions

override void Dispose (bool disposing)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableOpenCVObject
 DisposableOpenCVObject ()
 
 DisposableOpenCVObject (IntPtr ptr)
 
 DisposableOpenCVObject (bool isEnabledDispose)
 
 DisposableOpenCVObject (IntPtr ptr, bool isEnabledDispose)
 
- Protected Member Functions inherited from OpenCVForUnity.DisposableObject
 DisposableObject ()
 
 DisposableObject (bool isEnabledDispose)
 

Additional Inherited Members

- Properties inherited from OpenCVForUnity.DisposableObject
bool IsDisposed [get, protected set]
 
bool IsEnabledDispose [get, set]
 

Detailed Description

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:

Note
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

Constructor & Destructor Documentation

◆ VideoCapture() [1/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( )

Default constructor.

Note
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/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( string  filename,
int  apiPreference 
)

Opens a video file or a capturing device or an 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
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.
See also
cv::VideoCaptureAPIs

◆ VideoCapture() [3/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( string  filename)

Opens a video file or a capturing device or an 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
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.
See also
cv::VideoCaptureAPIs

◆ VideoCapture() [4/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( string  filename,
int  apiPreference,
MatOfInt  _params 
)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

◆ VideoCapture() [5/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( int  index,
int  apiPreference 
)

Opens 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
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.
See also
cv::VideoCaptureAPIs

◆ VideoCapture() [6/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( int  index)

Opens 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
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.
See also
cv::VideoCaptureAPIs

◆ VideoCapture() [7/7]

OpenCVForUnity.VideoioModule.VideoCapture.VideoCapture ( int  index,
int  apiPreference,
MatOfInt  _params 
)

Opens a camera for video capturing with API Preference and parameters.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties

Member Function Documentation

◆ __fromPtr__()

static VideoCapture OpenCVForUnity.VideoioModule.VideoCapture.__fromPtr__ ( IntPtr  addr)
static

◆ Dispose()

override void OpenCVForUnity.VideoioModule.VideoCapture.Dispose ( bool  disposing)
protectedvirtual

◆ get()

double OpenCVForUnity.VideoioModule.VideoCapture.get ( int  propId)

Returns the specified VideoCapture property.

Parameters
propIdProperty identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from videoio_flags_others
Returns
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.
Note
Reading / writing properties involves many layers. Some unexpected result might happens along this chain.
VideoCapture -&gt; API Backend -&gt; Operating System -&gt; Device Driver -&gt; Device Hardware
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()

string OpenCVForUnity.VideoioModule.VideoCapture.getBackendName ( )

Returns used backend API name.

Note
Stream should be opened.

◆ getExceptionMode()

bool OpenCVForUnity.VideoioModule.VideoCapture.getExceptionMode ( )

◆ getNativeObjAddr()

IntPtr OpenCVForUnity.VideoioModule.VideoCapture.getNativeObjAddr ( )

◆ grab()

bool OpenCVForUnity.VideoioModule.VideoCapture.grab ( )

Grabs the next frame from video file or capturing device.

Returns
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()

bool OpenCVForUnity.VideoioModule.VideoCapture.isOpened ( )

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/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( string  filename,
int  apiPreference 
)

Opens a video file or a capturing device or an 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&amp; filename, int apiPreference = CAP_ANY)
@return `true` if the file has been successfully opened

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

◆ open() [2/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( string  filename)

Opens a video file or a capturing device or an 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&amp; filename, int apiPreference = CAP_ANY)
@return `true` if the file has been successfully opened

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

◆ open() [3/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( string  filename,
int  apiPreference,
MatOfInt  _params 
)

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

@return `true` if the file has been successfully opened

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

◆ open() [4/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( int  index,
int  apiPreference 
)

Opens 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, int apiPreference = CAP_ANY)
@return `true` if the camera has been successfully opened.

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

◆ open() [5/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( int  index)

Opens 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, int apiPreference = CAP_ANY)
@return `true` if the camera has been successfully opened.

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

◆ open() [6/6]

bool OpenCVForUnity.VideoioModule.VideoCapture.open ( int  index,
int  apiPreference,
MatOfInt  _params 
)

Opens a camera for video capturing with API Preference and parameters.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

@return `true` if the camera has been successfully opened.

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

◆ read()

bool OpenCVForUnity.VideoioModule.VideoCapture.read ( Mat  image)

Grabs, decodes and returns the next video frame.

Parameters
[out]imagethe video frame is returned here. If no frames has been grabbed the image will be empty.
Returns
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()).

Note
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()

void OpenCVForUnity.VideoioModule.VideoCapture.release ( )

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() [1/2]

bool OpenCVForUnity.VideoioModule.VideoCapture.retrieve ( Mat  image,
int  flag 
)

Decodes and returns the grabbed video frame.

Parameters
[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
Returns
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()).

See also
read()
Note
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.

◆ retrieve() [2/2]

bool OpenCVForUnity.VideoioModule.VideoCapture.retrieve ( Mat  image)

Decodes and returns the grabbed video frame.

Parameters
[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
Returns
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()).

See also
read()
Note
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()

bool OpenCVForUnity.VideoioModule.VideoCapture.set ( int  propId,
double  value 
)

Sets a property in the VideoCapture.

Parameters
propIdProperty identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from videoio_flags_others
valueValue of the property.
Returns
true if the property is supported by backend used by the VideoCapture instance.
Note
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()

void OpenCVForUnity.VideoioModule.VideoCapture.setExceptionMode ( bool  enable)

Switches exceptions mode

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

The documentation for this class was generated from the following file: