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 : public 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
| Type | Kind | Summary |
|---|---|---|
| UsbCamera.DisconnectedEventHandler | Delegate | The handler of Disconnected |
| UsbCamera.FrameReceivedEventHandler | Delegate | The handler of FrameReceived |
Constructors
UsbCamera(string deviceName)
UsbCamera(const std::string& deviceName);
Opens the camera that UsbHostController reported ("/dev/video0").
Properties
Connected
bool Connected() const;
true while the camera is physically present on the USB bus.
Returns bool
DeviceName
std::string DeviceName() const;
What the camera was opened with: "/dev/video0"
Returns string
FrameRate
int32_t FrameRate() const;
The frame rate in use (frames per second)
Returns int
Height
int32_t Height() const;
The picture height in use
Returns int
IsStreaming
bool IsStreaming() const;
Whether StartStreaming is on
Returns bool
JpegQuality
int32_t JpegQuality() const;
void JpegQuality(int32_t value);
The JPEG quality (1 to 100) of pictures the library makes from raw YUYV pictures. Defaults to 85.
Returns int
Name
std::string Name() const;
The camera's name ("USB 2.0 Camera: USB Camera")
Returns string
PixelFormat
CameraPixelFormat PixelFormat() const;
What the camera sends for the size in use
Returns CameraPixelFormat
SupportedControls
IReadOnlyList<CameraControl> SupportedControls() const;
The controls this camera has
Returns IReadOnlyList<CameraControl>
SupportedFormats
IReadOnlyList<CameraFormat> SupportedFormats() const;
The sizes the camera has, with what it sends for each
Returns IReadOnlyList<CameraFormat>
Width
int32_t Width() const;
The picture width in use
Returns int
Methods
Capture(int timeout)
std::vector<uint8_t> Capture(int32_t timeout);
Takes a picture: a JPEG.
| Parameter | Type | Description |
|---|---|---|
timeout | int | How long to wait for the camera, in milliseconds (the first picture also waits for the exposure). |
Returns byte[]
Capture(string path)
void Capture(const std::string& path);
Takes a picture and saves it as a JPEG file.
Dispose()
void Dispose();
Stops the camera (a frame being delivered finishes first) and closes it
GetControl(CameraControl control)
CameraControlValue GetControl(CameraControl control);
A control's range and value.
Returns CameraControlValue
SetControl(CameraControl control, int value)
void SetControl(CameraControl control, int32_t value);
Sets a control, in the camera's own units (GetControl gives its range).
SetResolution(int width, int height, int frameRate)
void SetResolution(int32_t width, int32_t height, int32_t frameRate);
Uses a size the camera has (MJPEG if the camera has it at that size, else YUYV).
| Parameter | Type | Description |
|---|---|---|
width | int | The width, one of SupportedFormats'. |
height | int | The height. |
frameRate | int | Frames per second; 0: the camera's highest for that size. |
SetResolution(CameraFormat format, int frameRate)
void SetResolution(const CameraFormat& format, int32_t frameRate);
Uses one of SupportedFormats, as it is (YUYV too).
StartStreaming()
void StartStreaming();
Starts streaming: every frame comes as a JPEG in FrameReceived.
StopStreaming()
void StopStreaming();
Stops streaming; UsbCamera.FrameReceived no longer fires. A frame being delivered finishes first.
Events
Disconnected
Core::Event<...> Disconnected;
The camera was unplugged
FrameReceived
Core::Event<...> FrameReceived;
A frame while streaming (StartStreaming)