C# 클래스 Accord.Video.DirectShow.VideoCaptureDevice

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

This video source class captures video data from local video capture device, like USB web camera (or internal), frame grabber, capture board - anything which supports DirectShow interface. For devices which has a shutter button or support external software triggering, the class also allows to do snapshots. Both video size and snapshot size can be configured.

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 when you no longer need capturing videoSource.SignalToStop( ); // ... private void video_NewFrame( object sender, NewFrameEventArgs eventArgs ) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame }
상속: IVideoSource
파일 보기 프로젝트 열기: accord-net/framework 1 사용 예제들

Private Properties

프로퍼티 타입 설명
ColletCrossbarVideoInputs Accord.Video.DirectShow.VideoInput[]
DisplayPropertyPage void
Free void
GetCurrentCrossbarInput VideoInput
GetPinCapabilitiesAndConfigureSizeAndRate void
OnNewFrame void
OnSnapshotFrame void
SetCurrentCrossbarInput void
SetResolution void
WorkerThread void
WorkerThread void

공개 메소드들

메소드 설명
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.

GetCameraProperty ( CameraControlProperty property, int &value, CameraControlFlags &controlFlags ) : bool

Gets the current setting of a camera property.

GetCameraPropertyRange ( CameraControlProperty property, int &minValue, int &maxValue, int &stepSize, int &defaultValue, CameraControlFlags &controlFlags ) : bool

Gets the range and default value of a specified camera property.

SetCameraProperty ( CameraControlProperty property, int value, CameraControlFlags controlFlags ) : bool

Sets a specified property on the camera.

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.

VideoCaptureDevice ( string deviceMoniker, PixelFormat pixelFormat ) : 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 ) : Accord.Video.DirectShow.VideoInput[]
DisplayPropertyPage ( IntPtr parentWindow, object sourceObject ) : void
Free ( ) : void

Free resource.

GetCurrentCrossbarInput ( IAMCrossbar crossbar ) : VideoInput
GetPinCapabilitiesAndConfigureSizeAndRate ( ICaptureGraphBuilder2 graphBuilder, IBaseFilter baseFilter, System.Guid pinCategory, VideoCapabilities resolutionToSet, 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
SetResolution ( IAMStreamConfig streamConfig, VideoCapabilities resolution ) : 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

GetCameraProperty() 공개 메소드

Gets the current setting of a camera property.
Video source is not specified - device moniker is not set. Failed creating device object for moniker. The video source does not support camera control.
public GetCameraProperty ( CameraControlProperty property, int &value, CameraControlFlags &controlFlags ) : bool
property CameraControlProperty Specifies the property to retrieve.
value int Receives the value of the property.
controlFlags CameraControlFlags Receives the value indicating whether the setting is controlled manually or automatically
리턴 bool

GetCameraPropertyRange() 공개 메소드

Gets the range and default value of a specified camera property.
Video source is not specified - device moniker is not set. Failed creating device object for moniker. The video source does not support camera control.
public GetCameraPropertyRange ( CameraControlProperty property, int &minValue, int &maxValue, int &stepSize, int &defaultValue, CameraControlFlags &controlFlags ) : bool
property CameraControlProperty Specifies the property to query.
minValue int Receives the minimum value of the property.
maxValue int Receives the maximum value of the property.
stepSize int Receives the step size for the property.
defaultValue int Receives the default value of the property.
controlFlags CameraControlFlags Receives a member of the enumeration, indicating whether the property is controlled automatically or manually.
리턴 bool

SetCameraProperty() 공개 메소드

Sets a specified property on the camera.
Video source is not specified - device moniker is not set. Failed creating device object for moniker. The video source does not support camera control.
public SetCameraProperty ( CameraControlProperty property, int value, CameraControlFlags controlFlags ) : bool
property CameraControlProperty Specifies the property to set.
value int Specifies the new value of the property.
controlFlags CameraControlFlags Specifies the desired control setting.
리턴 bool

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

VideoCaptureDevice() 공개 메소드

Initializes a new instance of the VideoCaptureDevice class.
public VideoCaptureDevice ( string deviceMoniker, PixelFormat pixelFormat ) : System
deviceMoniker string Moniker string of video capture device.
pixelFormat PixelFormat Pixel format of video.
리턴 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