Skip to main content

UsbCamera Class

Package: GHIElectronics.Endpoint.Devices.Camera
Namespace: GHIElectronics.Endpoint.Devices.Camera

A webcam: any USB Video Class camera. Pictures come as JPEG files, whether the camera sends MJPEG or raw YUYV pictures.

public sealed class UsbCamera : IDisposable

Remarks​

Open it with the DeviceName of a Webcam from UsbHostController ("/dev/video0"). The first picture waits until the camera's automatic exposure has settled (about a second); while pictures are taken the camera keeps running, so the next ones come at once. At first the size is 640x480. The events come on the camera's own thread. A camera stays alive until it is disposed.

Nested Types​

TypeKindSummary
UsbCamera.DisconnectedEventHandlerDelegateThe handler of Disconnected
UsbCamera.FrameReceivedEventHandlerDelegateThe handler of FrameReceived

Constructors​

UsbCamera(string deviceName)​

public UsbCamera(string deviceName)

Opens the camera that UsbHostController reported ("/dev/video0").

Properties​

Connected​

public bool Connected { get; }

true while the camera is physically present on the USB bus.

Returns bool

DeviceName​

public string DeviceName { get; }

What the camera was opened with: "/dev/video0"

Returns string

FrameRate​

public int FrameRate { get; }

The frame rate in use (frames per second)

Returns int

Height​

public int Height { get; }

The picture height in use

Returns int

IsStreaming​

public bool IsStreaming { get; }

Whether StartStreaming is on

Returns bool

JpegQuality​

public int JpegQuality { get; set; }

The JPEG quality (1 to 100) of pictures the library makes from raw YUYV pictures. Defaults to 85.

Returns int

Name​

public string Name { get; }

The camera's name ("USB 2.0 Camera: USB Camera")

Returns string

PixelFormat​

public CameraPixelFormat PixelFormat { get; }

What the camera sends for the size in use

Returns CameraPixelFormat

SupportedControls​

public IReadOnlyList<CameraControl> SupportedControls { get; }

The controls this camera has

Returns IReadOnlyList<CameraControl>

SupportedFormats​

public IReadOnlyList<CameraFormat> SupportedFormats { get; }

The sizes the camera has, with what it sends for each

Returns IReadOnlyList<CameraFormat>

Width​

public int Width { get; }

The picture width in use

Returns int

Methods​

Capture(int timeout)​

public byte[] Capture(int timeout)

Takes a picture: a JPEG.

ParameterTypeDescription
timeoutintHow long to wait for the camera, in milliseconds (the first picture also waits for the exposure).

Returns byte[]

Capture(string path)​

public void Capture(string path)

Takes a picture and saves it as a JPEG file.

Dispose()​

public void Dispose()

Stops the camera (a frame being delivered finishes first) and closes it

GetControl(CameraControl control)​

public CameraControlValue GetControl(CameraControl control)

A control's range and value.

Returns CameraControlValue

SetControl(CameraControl control, int value)​

public void SetControl(CameraControl control, int value)

Sets a control, in the camera's own units (GetControl gives its range).

SetResolution(int width, int height, int frameRate)​

public void SetResolution(int width, int height, int frameRate)

Uses a size the camera has (MJPEG if the camera has it at that size, else YUYV).

ParameterTypeDescription
widthintThe width, one of SupportedFormats'.
heightintThe height.
frameRateintFrames per second; 0: the camera's highest for that size.

SetResolution(CameraFormat format, int frameRate)​

public void SetResolution(CameraFormat format, int frameRate)

Uses one of SupportedFormats, as it is (YUYV too).

StartStreaming()​

public void StartStreaming()

Starts streaming: every frame comes as a JPEG in FrameReceived.

StopStreaming()​

public void StopStreaming()

Stops streaming; UsbCamera.FrameReceived no longer fires. A frame being delivered finishes first.

Events​

Disconnected​

public event DisconnectedEventHandler Disconnected

The camera was unplugged

FrameReceived​

public event FrameReceivedEventHandler FrameReceived

A frame while streaming (StartStreaming)