C# Class AForge.Video.DirectShow.VideoCaptureDevice

Video source for local video capture device (for example USB webcam).

The video source captures video data from local video capture device. DirectShow is used for capturing.

Sample usage:

// enumerate video devices videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice ); // create video source VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString ); // set NewFrame event handler videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame ); // start the video source videoSource.Start( ); // ... // signal to stop videoSource.SignalToStop( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }
Inheritance: IVideoSource
Show file Open project: holisticware-admin/MonoVersal.AForgeNET Class Usage Examples

Public Methods

Method Description
CheckIfCrossbarAvailable ( ) : bool

Check if running video source provides crossbar for configuration.

The method reports if the video source provides crossbar configuration using DisplayCrossbarPropertyPage.

DisplayCrossbarPropertyPage ( IntPtr parentWindow ) : void

Display property page of video crossbar (Analog Video Crossbar filter).

The Analog Video Crossbar filter is modeled after a general switching matrix, with n inputs and m outputs. For example, a video card might have two external connectors: a coaxial connector for TV, and an S-video input. These would be represented as input pins on the filter. The displayed property page allows to configure the crossbar by selecting input of a video card to use.

This method can be invoked only when video source is running (IsRunning is ). Otherwise it generates exception.

Use CheckIfCrossbarAvailable method to check if running video source provides crossbar configuration.

DisplayPropertyPage ( IntPtr parentWindow ) : void

Display property window for the video capture device providing its configuration capabilities.

If you pass parent window's handle to this method, then the displayed property page will become modal window and none of the controls from the parent window will be accessible. In order to make it modeless it is required to pass IntPtr.Zero as parent window's handle.

SignalToStop ( ) : void

Signal video source to stop its work.

Signals video source to stop its background thread, stop to provide new frames and free resources.

SimulateTrigger ( ) : void

Simulates an external trigger.

The method simulates external trigger for video cameras, which support providing still image snapshots. The effect is equivalent as pressing camera's shutter button - a snapshot will be provided through SnapshotFrame event.

The ProvideSnapshots property must be set to to enable receiving snapshots.

Start ( ) : void

Start video source.

Starts video source and return execution to caller. Video source object creates background thread and notifies about new frames with the help of NewFrame event.

Stop ( ) : void

Stop video source.

Stops video source aborting its thread.

Since the method aborts background thread, its usage is highly not preferred and should be done only if there are no other options. The correct way of stopping camera is signaling it stop and then waiting for background thread's completion.

VideoCaptureDevice ( ) : System

Initializes a new instance of the VideoCaptureDevice class.

VideoCaptureDevice ( string deviceMoniker ) : System

Initializes a new instance of the VideoCaptureDevice class.

WaitForStop ( ) : void

Wait for video source has stopped.

Waits for source stopping after it was signalled to stop using SignalToStop method.

Private Methods

Method Description
ColletCrossbarVideoInputs ( IAMCrossbar crossbar ) : AForge.Video.DirectShow.VideoInput[]
DisplayPropertyPage ( IntPtr parentWindow, object sourceObject ) : void
Free ( ) : void

Free resource.

GetCurrentCrossbarInput ( IAMCrossbar crossbar ) : VideoInput
GetPinCapabilitiesAndConfigureSizeAndRate ( ICaptureGraphBuilder2 graphBuilder, IBaseFilter baseFilter, Guid pinCategory, Size size, int frameRate, VideoCapabilities &capabilities ) : void
OnNewFrame ( Bitmap image ) : void

Notifies clients about new frame.

OnSnapshotFrame ( Bitmap image ) : void

Notifies clients about new snapshot frame.

SetCurrentCrossbarInput ( IAMCrossbar crossbar, VideoInput videoInput ) : void
SetFrameSizeAndRate ( IAMStreamConfig streamConfig, Size size, int frameRate ) : void
WorkerThread ( ) : void

Worker thread.

WorkerThread ( bool runGraph ) : void

Method Details

CheckIfCrossbarAvailable() public method

Check if running video source provides crossbar for configuration.

The method reports if the video source provides crossbar configuration using DisplayCrossbarPropertyPage.

public CheckIfCrossbarAvailable ( ) : bool
return bool

DisplayCrossbarPropertyPage() public method

Display property page of video crossbar (Analog Video Crossbar filter).

The Analog Video Crossbar filter is modeled after a general switching matrix, with n inputs and m outputs. For example, a video card might have two external connectors: a coaxial connector for TV, and an S-video input. These would be represented as input pins on the filter. The displayed property page allows to configure the crossbar by selecting input of a video card to use.

This method can be invoked only when video source is running (IsRunning is ). Otherwise it generates exception.

Use CheckIfCrossbarAvailable method to check if running video source provides crossbar configuration.

The video source must be running in order to display crossbar property page. Crossbar configuration is not supported by currently running video source.
public DisplayCrossbarPropertyPage ( IntPtr parentWindow ) : void
parentWindow System.IntPtr Handle of parent window.
return void

DisplayPropertyPage() public method

Display property window for the video capture device providing its configuration capabilities.

If you pass parent window's handle to this method, then the displayed property page will become modal window and none of the controls from the parent window will be accessible. In order to make it modeless it is required to pass IntPtr.Zero as parent window's handle.

The video source does not support configuration property page.
public DisplayPropertyPage ( IntPtr parentWindow ) : void
parentWindow System.IntPtr Handle of parent window.
return void

SignalToStop() public method

Signal video source to stop its work.
Signals video source to stop its background thread, stop to provide new frames and free resources.
public SignalToStop ( ) : void
return void

SimulateTrigger() public method

Simulates an external trigger.

The method simulates external trigger for video cameras, which support providing still image snapshots. The effect is equivalent as pressing camera's shutter button - a snapshot will be provided through SnapshotFrame event.

The ProvideSnapshots property must be set to to enable receiving snapshots.

public SimulateTrigger ( ) : void
return void

Start() public method

Start video source.
Starts video source and return execution to caller. Video source object creates background thread and notifies about new frames with the help of NewFrame event.
public Start ( ) : void
return void

Stop() public method

Stop video source.

Stops video source aborting its thread.

Since the method aborts background thread, its usage is highly not preferred and should be done only if there are no other options. The correct way of stopping camera is signaling it stop and then waiting for background thread's completion.

public Stop ( ) : void
return void

VideoCaptureDevice() public method

Initializes a new instance of the VideoCaptureDevice class.
public VideoCaptureDevice ( ) : System
return System

VideoCaptureDevice() public method

Initializes a new instance of the VideoCaptureDevice class.
public VideoCaptureDevice ( string deviceMoniker ) : System
deviceMoniker string Moniker string of video capture device.
return System

WaitForStop() public method

Wait for video source has stopped.
Waits for source stopping after it was signalled to stop using SignalToStop method.
public WaitForStop ( ) : void
return void