C# Класс 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 }
Наследование: IVideoSource
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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

Описание методов

CheckIfCrossbarAvailable() публичный Метод

Check if running video source provides crossbar for configuration.

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

public CheckIfCrossbarAvailable ( ) : bool
Результат bool

DisplayCrossbarPropertyPage() публичный Метод

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.
Результат void

DisplayPropertyPage() публичный Метод

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.
Результат void

SignalToStop() публичный Метод

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
Результат void

SimulateTrigger() публичный Метод

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
Результат void

Start() публичный Метод

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
Результат void

Stop() публичный Метод

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
Результат void

VideoCaptureDevice() публичный Метод

Initializes a new instance of the VideoCaptureDevice class.
public VideoCaptureDevice ( ) : System
Результат System

VideoCaptureDevice() публичный Метод

Initializes a new instance of the VideoCaptureDevice class.
public VideoCaptureDevice ( string deviceMoniker ) : System
deviceMoniker string Moniker string of video capture device.
Результат System

WaitForStop() публичный Метод

Wait for video source has stopped.
Waits for source stopping after it was signalled to stop using SignalToStop method.
public WaitForStop ( ) : void
Результат void