Camera:constructor([devices], [parent], [x], [y], [width], [height])constructor
The Camera constructor initializes a new camera capture session using the specified devices.
The constructor blocks until the first camera frame has been received, ensuring the Camera is ready to use immediately after construction.- Camera behaves differently depending on whether the
ui module has been loaded before capture. - When
ui is loaded first, Camera is a widget (available in the ui module), that renders a live preview inside a child window. It requires a parent widget and accepts position and size arguments. - When
ui is not loaded, Camera is a plain object used for headless capture only (snapshot and recording). No preview window is created and no positional arguments are accepted.
- If no
devices table is provided, the system default video and audio devices are used. - Raises an error if no video or audio device is found on the system.
Parameters
[devices]
An optional
table specifying which capture devices to use. It may contain:
video: the name of the video capture device as a string (from capture.devices.video)audio: the name of the audio capture device as a string (from capture.devices.audio)
If omitted, the system default devices are used.
[parent]
The parent widget. Required when using Camera as a widget (i.e. when the
ui module is loaded first).
[x]
Horizontal position of the Camera widget in pixels, relative to its parent. Defaults to
0. Only used in widget mode.
[y]
Vertical position of the Camera widget in pixels, relative to its parent. Defaults to
0. Only used in widget mode.
[width]
Width of the Camera widget in pixels. Defaults to
320. Only used in widget mode.
[height]
Height of the Camera widget in pixels. Defaults to
240. Only used in widget mode.
Return value
Returns a new
Camera instance, or raises an error if initialization fails.
Example
--! luart-extensions
import ui, capture
-- Camera as a widget using the default devices
local win = ui.Window("Camera Preview", 640, 520)
local cam = ui.Camera(win, 10, 10, 620, 460)
cam.align = "all"
cam.aspect = "16x9"
await win:showasync()