Show / Hide Table of Contents

Class VideoCapture

Video capturing class

Inheritance
System.Object
DisposableObject
DisposableCvObject
VideoCapture
Implements
ICvPtrHolder
Inherited Members
DisposableCvObject.ptr
DisposableCvObject.CvPtr
DisposableObject.DataHandle
DisposableObject.IsDisposed
DisposableObject.IsEnabledDispose
DisposableObject.AllocatedMemory
DisposableObject.AllocatedMemorySize
DisposableObject.Dispose()
DisposableObject.Dispose(Boolean)
DisposableObject.DisposeManaged()
DisposableObject.AllocGCHandle(Object)
DisposableObject.AllocMemory(Int32)
DisposableObject.NotifyMemoryPressure(Int64)
DisposableObject.ThrowIfDisposed()
Namespace: OpenCvSharp
Assembly: OpenCvSharp.dll
Syntax
public class VideoCapture : DisposableCvObject, ICvPtrHolder

Constructors

| Improve this Doc View Source

VideoCapture()

Initializes empty capture. To use this, you should call Open.

Declaration
public VideoCapture()
| Improve this Doc View Source

VideoCapture(IntPtr)

Initializes from native pointer

Declaration
protected VideoCapture(IntPtr ptr)
Parameters
Type Name Description
IntPtr ptr

CvCapture*

| Improve this Doc View Source

VideoCapture(Int32, VideoCaptureAPIs)

Opens a camera for video capturing

Declaration
public VideoCapture(int index, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.Int32 index

id 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)

VideoCaptureAPIs apiPreference

preferred 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.

| Improve this Doc View Source

VideoCapture(Int32, VideoCaptureAPIs, VideoCapturePara)

Opens a camera for video capturing with API Preference and parameters

Declaration
public VideoCapture(int index, VideoCaptureAPIs apiPreference, VideoCapturePara prms)
Parameters
Type Name Description
System.Int32 index

id 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)

VideoCaptureAPIs apiPreference

preferred 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.

VideoCapturePara prms

Parameters of VideoCapture for hardware acceleration

| Improve this Doc View Source

VideoCapture(Int32, VideoCaptureAPIs, Int32[])

Opens a camera for video capturing with API Preference and parameters

Declaration
public VideoCapture(int index, VideoCaptureAPIs apiPreference, int[] prms)
Parameters
Type Name Description
System.Int32 index

id 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)

VideoCaptureAPIs apiPreference

preferred 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.

System.Int32[] prms

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

| Improve this Doc View Source

VideoCapture(String, VideoCaptureAPIs)

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

Declaration
public VideoCapture(string fileName, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.String fileName

it can be:

  • name of video file (e.g. video.avi)
  • or image sequence (e.g. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  • or URL of video stream (e.g. protocol://host:port/script_name?script_params|auth). 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.
VideoCaptureAPIs apiPreference

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.

| Improve this Doc View Source

VideoCapture(String, VideoCaptureAPIs, VideoCapturePara)

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

Declaration
public VideoCapture(string fileName, VideoCaptureAPIs apiPreference, VideoCapturePara prms)
Parameters
Type Name Description
System.String fileName

it can be:

  • name of video file (e.g. video.avi)
  • or image sequence (e.g. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  • or URL of video stream (e.g. protocol://host:port/script_name?script_params|auth). 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.
VideoCaptureAPIs apiPreference

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.

VideoCapturePara prms

Parameters of VideoCature for hardware acceleration

| Improve this Doc View Source

VideoCapture(String, VideoCaptureAPIs, Int32[])

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

Declaration
public VideoCapture(string fileName, VideoCaptureAPIs apiPreference, int[] prms)
Parameters
Type Name Description
System.String fileName

it 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). 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.
VideoCaptureAPIs apiPreference

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.

System.Int32[] prms

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

Properties

| Improve this Doc View Source

AutoExposure

exposure control done by camera, user can adjust refernce level using this feature [CV_CAP_PROP_AUTO_EXPOSURE]

Declaration
public double AutoExposure { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

AutoFocus

Declaration
public bool AutoFocus { get; set; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

BackLight

Declaration
public double BackLight { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Brightness

Gets or sets brightness of image (only for cameras)

Declaration
public double Brightness { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

BufferSize

Declaration
public double BufferSize { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

CaptureType

Gets the capture type (File or Camera)

Declaration
public CaptureType CaptureType { get; }
Property Value
Type Description
CaptureType
| Improve this Doc View Source

Contrast

Gets or sets contrast of image (only for cameras)

Declaration
public double Contrast { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

ConvertRgb

Boolean flags indicating whether images should be converted to RGB

Declaration
public bool ConvertRgb { get; set; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

Exposure

Exposure (only for cameras)

Declaration
public double Exposure { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Focus

Declaration
public double Focus { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Format

The format of the Mat objects returned by retrieve()

Declaration
public int Format { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

FourCC

Gets or sets 4-character code of codec

Declaration
public string FourCC { get; set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

Fps

Gets or sets frame rate

Declaration
public double Fps { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

FrameCount

Gets number of frames in video file

Declaration
public int FrameCount { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

FrameHeight

Gets or sets height of frames in the video stream

Declaration
public int FrameHeight { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

FrameWidth

Gets or sets width of frames in the video stream

Declaration
public int FrameWidth { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Gain

Gain of the image (only for cameras)

Declaration
public double Gain { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Gamma

Declaration
public double Gamma { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

GStreamerQueueLength

default is 1 [CV_CAP_GSTREAMER_QUEUE_LENGTH]

Declaration
public double GStreamerQueueLength { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Guid

Declaration
public double Guid { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Hue

Gets or sets hue of image (only for cameras)

Declaration
public double Hue { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Iris

Declaration
public double Iris { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

IsoSpeed

Declaration
public double IsoSpeed { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Mode

A backend-specific value indicating the current capture mode

Declaration
public int Mode { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Monocrome

Declaration
public double Monocrome { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_Baseline

in mm [CV_CAP_PROP_OPENNI_BASELINE]

Declaration
public double OpenNI_Baseline { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_DepthGeneratorBaseline

[CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE]

Declaration
public double OpenNI_DepthGeneratorBaseline { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_DepthGeneratorFocalLength

[CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH]

Declaration
public double OpenNI_DepthGeneratorFocalLength { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_DepthGeneratorRegistrationON

[CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON]

Declaration
public double OpenNI_DepthGeneratorRegistrationON { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_FocalLength

in pixels [CV_CAP_PROP_OPENNI_FOCAL_LENGTH]

Declaration
public double OpenNI_FocalLength { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_FrameMaxDepth

in mm [CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH]

Declaration
public double OpenNI_FrameMaxDepth { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_ImageGeneratorOutputMode

[CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE]

Declaration
public double OpenNI_ImageGeneratorOutputMode { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_OutputMode

[CV_CAP_PROP_OPENNI_OUTPUT_MODE]

Declaration
public double OpenNI_OutputMode { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

OpenNI_Registration

flag that synchronizes the remapping depth map to image map by changing depth generator's view point (if the flag is "on") or sets this view point to its normal one (if the flag is "off"). [CV_CAP_PROP_OPENNI_REGISTRATION]

Declaration
public double OpenNI_Registration { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Pan

Declaration
public double Pan { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

PosAviRatio

Gets or sets relative position of video file

Declaration
public CapturePosAviRatio PosAviRatio { get; set; }
Property Value
Type Description
CapturePosAviRatio
| Improve this Doc View Source

PosFrames

Gets or sets 0-based index of the frame to be decoded/captured next

Declaration
public int PosFrames { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

PosMsec

Gets or sets film current position in milliseconds or video capture timestamp

Declaration
public int PosMsec { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

PvAPIMulticastIP

ip for anable multicast master mode. 0 for disable multicast [CV_CAP_PROP_PVAPI_MULTICASTIP]

Declaration
public double PvAPIMulticastIP { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Rectification

TOWRITE (note: only supported by DC1394 v 2.x backend currently)

Declaration
public double Rectification { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Roll

Declaration
public double Roll { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Saturation

Gets or sets saturation of image (only for cameras)

Declaration
public double Saturation { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Settings

Declaration
public double Settings { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Sharpness

Declaration
public double Sharpness { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Temperature

[CV_CAP_PROP_TEMPERATURE]

Declaration
public double Temperature { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Tilt

Declaration
public double Tilt { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Trigger

Declaration
public double Trigger { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

TriggerDelay

Declaration
public double TriggerDelay { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

WhiteBalanceBlueU

Declaration
public double WhiteBalanceBlueU { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

WhiteBalanceRedV

Declaration
public double WhiteBalanceRedV { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_AEAG

Automatic exposure/gain [CV_CAP_PROP_XI_AEAG]

Declaration
public double XI_AEAG { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_AEAGLevel

default is 1 [CV_CAP_PROP_XI_AEAG_LEVEL]

Declaration
public double XI_AEAGLevel { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_AEMaxLimit

Maximum limit of exposure in AEAG procedure [CV_CAP_PROP_XI_AE_MAX_LIMIT]

Declaration
public double XI_AEMaxLimit { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_AGMaxLimit

Maximum limit of gain in AEAG procedure [CV_CAP_PROP_XI_AG_MAX_LIMIT]

Declaration
public double XI_AGMaxLimit { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_AutoWB

Automatic white balance [CV_CAP_PROP_XI_AUTO_WB]

Declaration
public double XI_AutoWB { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_DataFormat

Output data format. [CV_CAP_PROP_XI_DATA_FORMAT]

Declaration
public double XI_DataFormat { get; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_Downsampling

Change image resolution by binning or skipping.
[CV_CAP_PROP_XI_DOWNSAMPLING]

Declaration
public double XI_Downsampling { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_ExpPriority

Exposure priority (0.5 - exposure 50%, gain 50%). [CV_CAP_PROP_XI_EXP_PRIORITY]

Declaration
public double XI_ExpPriority { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_GpiLevel

Get general purpose level [CV_CAP_PROP_XI_GPI_LEVEL]

Declaration
public double XI_GpiLevel { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_GpiMode

Set general purpose input mode [CV_CAP_PROP_XI_GPI_MODE]

Declaration
public double XI_GpiMode { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_GpiSelector

Selects general purpose input [CV_CAP_PROP_XI_GPI_SELECTOR]

Declaration
public double XI_GpiSelector { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_GpoMode

Set general purpose output mode [CV_CAP_PROP_XI_GPO_MODE]

Declaration
public double XI_GpoMode { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_GpoSelector

Selects general purpose output [CV_CAP_PROP_XI_GPO_SELECTOR]

Declaration
public double XI_GpoSelector { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_LedMode

Define camera signalling LED functionality [CV_CAP_PROP_XI_LED_MODE]

Declaration
public double XI_LedMode { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_LedSelector

Selects camera signalling LED [CV_CAP_PROP_XI_LED_SELECTOR]

Declaration
public double XI_LedSelector { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_ManualWB

Calculates White Balance(must be called during acquisition) [CV_CAP_PROP_XI_MANUAL_WB]

Declaration
public double XI_ManualWB { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_OffsetX

Horizontal offset from the origin to the area of interest (in pixels). [CV_CAP_PROP_XI_OFFSET_X]

Declaration
public double XI_OffsetX { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_OffsetY

Vertical offset from the origin to the area of interest (in pixels). [CV_CAP_PROP_XI_OFFSET_Y]

Declaration
public double XI_OffsetY { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_Timeout

default is 1 [CV_CAP_PROP_XI_TIMEOUT]

Declaration
public double XI_Timeout { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_TrgSoftware

Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE. [CV_CAP_PROP_XI_TRG_SOFTWARE]

Declaration
public double XI_TrgSoftware { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

XI_TrgSource

Defines source of trigger. [CV_CAP_PROP_XI_TRG_SOURCE]

Declaration
public double XI_TrgSource { get; set; }
Property Value
Type Description
System.Double
| Improve this Doc View Source

Zoom

Declaration
public double Zoom { get; set; }
Property Value
Type Description
System.Double

Methods

| Improve this Doc View Source

DisposeUnmanaged()

Releases unmanaged resources

Declaration
protected override void DisposeUnmanaged()
Overrides
DisposableCvObject.DisposeUnmanaged()
| Improve this Doc View Source

FromCamera(Int32, VideoCaptureAPIs)

Opens a camera for video capturing

Declaration
public static VideoCapture FromCamera(int index, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.Int32 index

id 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)

VideoCaptureAPIs apiPreference

preferred 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.

Returns
Type Description
VideoCapture
| Improve this Doc View Source

FromFile(String, VideoCaptureAPIs)

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

Declaration
public static VideoCapture FromFile(string fileName, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.String fileName

it can be:

  • name of video file (e.g. video.avi)
  • or image sequence (e.g. img_%02d.jpg, which will read samples like img_00.jpg, img_01.jpg, img_02.jpg, ...)
  • or URL of video stream (e.g. protocol://host:port/script_name?script_params|auth). 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.
VideoCaptureAPIs apiPreference

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.

Returns
Type Description
VideoCapture
| Improve this Doc View Source

Get(VideoCaptureProperties)

Returns the specified VideoCapture property

Declaration
public double Get(VideoCaptureProperties propertyId)
Parameters
Type Name Description
VideoCaptureProperties propertyId

Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others

Returns
Type Description
System.Double

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.

| Improve this Doc View Source

Get(Int32)

Returns the specified VideoCapture property

Declaration
public double Get(int propertyId)
Parameters
Type Name Description
System.Int32 propertyId

Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others

Returns
Type Description
System.Double

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.

| Improve this Doc View Source

GetBackendName()

Returns used backend API name. Note that stream should be opened.

Declaration
public string GetBackendName()
Returns
Type Description
System.String
| Improve this Doc View Source

GetExceptionMode()

query if exception mode is active

Declaration
public bool GetExceptionMode()
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Grab()

Grabs the next frame from video file or capturing device.

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.

Declaration
public bool Grab()
Returns
Type Description
System.Boolean

true (non-zero) in the case of success.

| Improve this Doc View Source

IsOpened()

Returns true if video capturing has been initialized already.

Declaration
public bool IsOpened()
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Open(Int32, VideoCaptureAPIs)

Opens a camera for video capturing

Declaration
public bool Open(int index, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.Int32 index

id 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)

VideoCaptureAPIs apiPreference

preferred 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.

Returns
Type Description
System.Boolean

true if the file has been successfully opened

| Improve this Doc View Source

Open(String, VideoCaptureAPIs)

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

Declaration
public bool Open(string fileName, VideoCaptureAPIs apiPreference = VideoCaptureAPIs.ANY)
Parameters
Type Name Description
System.String fileName

it 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). 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.
VideoCaptureAPIs apiPreference

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.

Returns
Type Description
System.Boolean

true if the file has been successfully opened

| Improve this Doc View Source

Read(Mat)

Grabs, decodes and returns the next video frame.

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

Declaration
public bool Read(Mat image)
Parameters
Type Name Description
Mat image
Returns
Type Description
System.Boolean

false if no frames has been grabbed

| Improve this Doc View Source

Read(OutputArray)

Grabs, decodes and returns the next video frame.

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

Declaration
public bool Read(OutputArray image)
Parameters
Type Name Description
OutputArray image
Returns
Type Description
System.Boolean

false if no frames has been grabbed

| Improve this Doc View Source

Release()

Closes video file or capturing device.

Declaration
public void Release()
| Improve this Doc View Source

Retrieve(Mat, CameraChannels)

Decodes and returns the grabbed video frame.

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

Declaration
public bool Retrieve(Mat image, CameraChannels streamIdx)
Parameters
Type Name Description
Mat image

the video frame is returned here. If no frames has been grabbed the image will be empty.

CameraChannels streamIdx

non-zero streamIdx is only valid for multi-head camera live streams

Returns
Type Description
System.Boolean
| Improve this Doc View Source

Retrieve(Mat, Int32)

Decodes and returns the grabbed video frame.

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

Declaration
public bool Retrieve(Mat image, int flag = 0)
Parameters
Type Name Description
Mat image

the video frame is returned here. If no frames has been grabbed the image will be empty.

System.Int32 flag

it could be a frame index or a driver specific flag

Returns
Type Description
System.Boolean
| Improve this Doc View Source

Retrieve(OutputArray, CameraChannels)

Decodes and returns the grabbed video frame.

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

Declaration
public bool Retrieve(OutputArray image, CameraChannels streamIdx)
Parameters
Type Name Description
OutputArray image

the video frame is returned here. If no frames has been grabbed the image will be empty.

CameraChannels streamIdx

non-zero streamIdx is only valid for multi-head camera live streams

Returns
Type Description
System.Boolean
| Improve this Doc View Source

Retrieve(OutputArray, Int32)

Decodes and returns the grabbed video frame.

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

Declaration
public bool Retrieve(OutputArray image, int flag = 0)
Parameters
Type Name Description
OutputArray image

the video frame is returned here. If no frames has been grabbed the image will be empty.

System.Int32 flag

it could be a frame index or a driver specific flag

Returns
Type Description
System.Boolean
| Improve this Doc View Source

RetrieveMat()

Decodes and returns the grabbed video frame.

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

Declaration
public Mat RetrieveMat()
Returns
Type Description
Mat

the video frame is returned here. If no frames has been grabbed the image will be empty.

| Improve this Doc View Source

Set(VideoCaptureProperties, Double)

Sets a property in the VideoCapture.

Declaration
public bool Set(VideoCaptureProperties propertyId, double value)
Parameters
Type Name Description
VideoCaptureProperties propertyId

Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others

System.Double value

Value of the property.

Returns
Type Description
System.Boolean

true if the property is supported by backend used by the VideoCapture instance.

| Improve this Doc View Source

Set(Int32, Double)

Sets a property in the VideoCapture.

Declaration
public bool Set(int propertyId, double value)
Parameters
Type Name Description
System.Int32 propertyId

Property identifier from cv::VideoCaptureProperties (eg. cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...) or one from @ref videoio_flags_others

System.Double value

Value of the property.

Returns
Type Description
System.Boolean

true if the property is supported by backend used by the VideoCapture instance.

| Improve this Doc View Source

SetExceptionMode(Boolean)

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

Declaration
public void SetExceptionMode(bool enable)
Parameters
Type Name Description
System.Boolean enable
| Improve this Doc View Source

WaitAny(IEnumerable<VideoCapture>, out Int32[], Int64)

Wait for ready frames from VideoCapture.

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.

Declaration
public static bool WaitAny(IEnumerable<VideoCapture> streams, out int[] readyIndex, long timeoutNs = 0L)
Parameters
Type Name Description
IEnumerable<VideoCapture> streams

input video streams

System.Int32[] readyIndex

stream indexes with grabbed frames (ready to use .retrieve() to fetch actual frame)

System.Int64 timeoutNs

number of nanoseconds (0 - infinite)

Returns
Type Description
System.Boolean

`true if streamReady is not empty

Exceptions
Type Condition
OpenCVException

Exception %Exception on stream errors (check .isOpened() to filter out malformed streams) or VideoCapture type is not supported

Implements

ICvPtrHolder
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX