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.

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)​

def __init__(self, deviceName: str):

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

Properties​

Connected​

Connected: bool # @property

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

Returns bool

DeviceName​

DeviceName: str # @property

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

Returns string

FrameRate​

FrameRate: int # @property

The frame rate in use (frames per second)

Returns int

Height​

Height: int # @property

The picture height in use

Returns int

IsStreaming​

IsStreaming: bool # @property

Whether StartStreaming is on

Returns bool

JpegQuality​

JpegQuality: int # @property / @setter

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

Returns int

Name​

Name: str # @property

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

Returns string

PixelFormat​

PixelFormat: CameraPixelFormat # @property

What the camera sends for the size in use

Returns CameraPixelFormat

SupportedControls​

SupportedControls: IReadOnlyList[CameraControl] # @property

The controls this camera has

Returns IReadOnlyList<CameraControl>

SupportedFormats​

SupportedFormats: IReadOnlyList[CameraFormat] # @property

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

Returns IReadOnlyList<CameraFormat>

Width​

Width: int # @property

The picture width in use

Returns int

Methods​

Capture(int timeout)​

def Capture(self, timeout: int) -> list[int]:

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)​

def Capture(self, path: str) -> None:

Takes a picture and saves it as a JPEG file.

Dispose()​

def Dispose(self) -> None:

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

GetControl(CameraControl control)​

def GetControl(self, control: CameraControl) -> CameraControlValue:

A control's range and value.

Returns CameraControlValue

SetControl(CameraControl control, int value)​

def SetControl(self, control: CameraControl, value: int) -> None:

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

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

def SetResolution(self, width: int, height: int, frameRate: int) -> None:

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)​

def SetResolution(self, format: CameraFormat, frameRate: int) -> None:

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

StartStreaming()​

def StartStreaming(self) -> None:

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

StopStreaming()​

def StopStreaming(self) -> None:

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

Events​

Disconnected​

Disconnected # += / -= handler

The camera was unplugged

FrameReceived​

FrameReceived # += / -= handler

A frame while streaming (StartStreaming)