VideoCaptureDevice Class |
Namespace: Accord.Video.DirectShow
The VideoCaptureDevice type exposes the following members.
Name | Description | |
---|---|---|
VideoCaptureDevice |
Initializes a new instance of the VideoCaptureDevice class.
| |
VideoCaptureDevice(String) |
Initializes a new instance of the VideoCaptureDevice class.
| |
VideoCaptureDevice(String, PixelFormat) |
Initializes a new instance of the VideoCaptureDevice class.
|
Name | Description | |
---|---|---|
AvailableCrossbarVideoInputs |
Available inputs of the video capture card.
| |
BytesReceived |
Received bytes count.
| |
CrossbarVideoInput |
Current video input of capture card.
| |
DesiredAverageTimePerFrame |
The desired average display time of the video frames, in 100-nanosecond units.
There is no guarantee that the device will actually respect this setting, however
some devices will not work unless this property is set. See remarks for details.
| |
DesiredFrameRate | Obsolete.
Obsolete - no longer in use.
| |
DesiredFrameSize | Obsolete.
Obsolete - no longer in use
| |
DesiredSnapshotSize | Obsolete.
Obsolete - no longer in use
| |
FramesReceived |
Received frames count.
| |
IsRunning |
State of the video source.
| |
ProvideSnapshots |
Specifies if snapshots should be provided or not.
| |
SnapshotCapabilities |
Snapshot capabilities of the device.
| |
SnapshotResolution |
Snapshot resolution to set.
| |
Source |
Video source.
| |
SourceObject |
Source COM object of camera capture device.
| |
VideoCapabilities |
Video capabilities of the device.
| |
VideoResolution |
Video resolution to set.
|
Name | Description | |
---|---|---|
CheckIfCrossbarAvailable |
Check if running video source provides crossbar for configuration.
| |
DisplayCrossbarPropertyPage |
Display property page of video crossbar (Analog Video Crossbar filter).
| |
DisplayPropertyPage |
Display property window for the video capture device providing its configuration
capabilities.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetCameraProperty |
Gets the current setting of a camera property.
| |
GetCameraPropertyRange |
Gets the range and default value of a specified camera property.
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
SetCameraProperty |
Sets a specified property on the camera.
| |
SignalToStop |
Signal video source to stop its work.
| |
SimulateTrigger |
Simulates an external trigger.
| |
Start |
Start video source.
| |
Stop |
Stop video source.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
WaitForStop |
Wait for video source has stopped.
|
Name | Description | |
---|---|---|
NewFrame |
New frame event.
| |
PlayingFinished |
Video playing finished event.
| |
SnapshotFrame |
Snapshot frame event.
| |
VideoSourceError |
Video source error event.
|
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
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.
// To use the VideoCaptureClass, the first step is to enumerate the different // video capture devices in your system. The output of the method below should // include any webcam currently attached to or integrated into your computer: var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); // A possible output will be: // "{ Integrated Webcam(@device:pnp:\\?\usb#vid_0c45&pid_6713&mi_00#6&4851259&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global)}" // Now, we can create a video source selecting one of the devices. For this, // pass the DirectShow device moniker (a kind of device identifier) of the // device you would like to capture from to VideoCaptureDevice: var videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString); // Then, we just have to define what we would like to do once the device send // us a new frame. This can be done using standard .NET events (the actual // contents of the video_NewFrame method is shown at the bottom of this page) videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); // Start the video source. This is not a blocking operation, meaning that // the frame capturing routine will actually be running in a different thread // and execution will be returned to the caller while the capture happens in // the background: videoSource.Start(); // ... // Let's say our application continues running, and after a while we decide // to stop capturing frames from the device. To stop the device, we can use videoSource.SignalToStop(); // Note that this is again a non-blocking operation. The device will continue // capturing for a few milliseconds until it gets notified about our request.
The video_NewFrame event could have been defined as in any of the following examples:
// The video_NewFrame used in the example above could be defined as: private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { // get new frame Bitmap bitmap = eventArgs.Frame; // process the frame (you can do anything with it, such as running an // image processing filter, saving it to disk, showing on screen, etc) }
// This is anowher example on how the video_NewFrame could have been // defined. In this example, we will apply a grayscale filter to the // images as they arrive from the capture device. // When processing multiple frames, it is better to try to cache // all operations and memory allocations outside of the main loop: Grayscale grayscale = Grayscale.CommonAlgorithms.BT709; // The video_NewFrame used in the example above could be defined as: private void video_NewFrame2(object sender, NewFrameEventArgs eventArgs) { // get new frame Bitmap bitmap = eventArgs.Frame; // Apply the filter we have cached outside: Bitmap grayBitmap = grayscale.Apply(bitmap); // process the frame (you can do anything with it, such as running an // image processing filter, saving it to disk, showing on screen, etc) }