class: webcam_capture_module
[23:14] static extends: object
Module JAR loader class.
Methods
- webcam_capture_module ()
class: Webcam
[61:14] (extern: com.lehman.aussom.Webcam) extends: object
Represents one physical webcam device.
Methods
-
Webcam ()
Default constructor.
-
getName ()
Gets the webcam device name. This function takes no options.
- @r
Astring with the device name.
- @r
-
open (
bool Async = true)Opens the webcam for capture. Async mode is required to use the streaming methods latestFrame(), nextFrame(), and startStream(). When Async is true a background thread grabs frames continuously at the rate set by setFps(); getImageBytes() and saveImage() return the most recent cached frame. When Async is false the webcam runs in pull-only mode and getImageBytes() blocks while it grabs each frame on demand. Set the capture size with setViewSize() or setResolution() before calling open().
- @p
Asyncis an optional bool. The default is true. - @r
Thisobject.
- @p
-
close ()
Closes the webcam and releases the device. This function takes no options. Calling close() on a closed webcam is allowed. Stops any running stream before releasing the device.
- @r
Thisobject.
- @r
-
isOpen ()
Checks whether the webcam is open. This function takes no options.
- @r
Abool with true if the webcam is open and false if not.
- @r
-
getViewSize ()
Gets the current capture size. This function takes no options.
- @r
Atwo item list containing width and height.
- @r
-
getViewSizes ()
Gets the capture sizes supported by this webcam driver. This function takes no options. Use one of the returned [width, height] pairs when calling setViewSize().
- @r
Alist of two item lists. Each child list contains width and height.
- @r
-
setViewSize (
int Width, int Height)Sets the capture size. This should be called before open(). Width and Height must be one of the [width, height] pairs returned by getViewSizes() for this camera. Common examples include 160x120, 320x240, 640x480, 1280x720, and 1920x1080, but the real options are device-specific.
- @p
Widthis an int with the capture width from getViewSizes(). - @p
Heightis an int with the capture height from getViewSizes(). - @r
Thisobject.
- @p
-
setResolution (
string Name)Sets the capture size from a WebcamResolution enum name. This should be called before open(). Available names are QQVGA, HQVGA, QVGA, WQVGA, HVGA, VGA, WVGA, FWVGA, SVGA, DVGA, WSVGA1, WSVGA2, XGA, XGAP, WXGA1, WXGA2, WXGAP, SXGA, SXGAP, WSXGAP, UXGA, WUXGA, QWXGA, QXGA, WQXGA, QSXGA, WQSXGA, QUXGA, WQUXGA, HXGA, WHXGA, HSXGA, WHSXGA, HUXGA, WHUXGA, NHD, QHD, HD, HDP, FHD, FHDP, DCI2K, WQHD, WQHDP, UWQHD, UW4K, UHD4K, DCI4K, UW5K, UHDP5K, UW8K, UHD8K, PAL, and CIF. The name must exist in the library and the selected camera must support that size. Use getViewSizes() when you need the exact sizes reported by the active device.
- @p
Nameis a string with a WebcamResolution enum name. - @r
Thisobject.
- @p
-
setFps (
double Fps)Sets the target capture rate of the underlying frame updater. The rate is a soft cap, not a guarantee. The default is 9.6 frames per second. Only takes effect in async mode. Call before open() or while the webcam is open.
- @p
Fpsis a double with the target frames per second. Must be greater than zero. - @r
Thisobject.
- @p
-
getFps ()
Returns the target capture rate of the underlying frame updater.
- @r
Adouble with the target frames per second.
- @r
-
getImageBytes (
string Format = "png")Captures one frame and returns encoded image bytes. In async mode this returns the most recent cached frame. In sync mode it grabs a fresh frame from the device. Format must be an ImageIO writer format name. Common built-in Java options are png, jpg, jpeg, gif, bmp, and wbmp. Some Java runtimes also provide tif or tiff. Format names are case-insensitive.
- @p
Formatis an optional ImageIO format name. The default is png. - @r
ABuffer containing the encoded image.
- @p
-
saveImage (
string Path, string Format = null)Captures one frame and saves it to disk. Format must be an ImageIO writer format name. Common built-in Java options are png, jpg, jpeg, gif, bmp, and wbmp. Some Java runtimes also provide tif or tiff. Format names are case-insensitive. If Format is null, the file extension from Path is used.
- @p
Pathis a string with the image output path. The parent directory must exist. - @p
Formatis an optional ImageIO format name or null to use the file extension. - @r
Thisobject.
- @p
-
latestFrame (
string Format = "png")Returns the most recent cached frame as encoded image bytes. Non-blocking. Returns null when no frame has arrived yet. Requires the webcam to be open in async mode. Useful for a JavaFX preview driven by an AnimationTimer that pulls frames on its own clock.
- @p
Formatis an optional ImageIO format name. The default is png. - @r
ABuffer with the encoded frame, or null when no frame is available.
- @p
-
nextFrame (
int TimeoutMs = 0, string Format = "png")Blocks until a fresh frame arrives, then returns its encoded bytes. Each call returns a frame newer than the one returned by the previous call on this Webcam object. If the consumer is slow, intermediate frames are dropped silently and the call returns the latest one. Requires the webcam to be open in async mode.
- @p
TimeoutMsis an int with the maximum wait time in milliseconds. A value of zero or less waits forever. The default is zero. - @p
Formatis an optional ImageIO format name. The default is png. - @r
ABuffer with the encoded frame, or null when the timeout elapses.
- @p
-
startStream (
callback OnFrame, double Fps = 30.0, string Format = "png")Starts a push stream that calls the provided callback for each new frame. Requires the webcam to be open in async mode. The callback receives one Buffer argument with the encoded frame bytes. The callback runs on a background stream thread, not on the Aussom main thread. Slow callbacks slow the loop and cause frames to be dropped silently; the loop never queues frames. IMPORTANT: When using JavaFX, scene-graph nodes such as ImageView and WritableImage may only be touched from the JavaFX Application Thread. A startStream callback that writes directly into a scene-graph node will throw "Not on FX application thread". Marshal those writes back onto the FX thread (for example with fxapp.runLater(...)), or use latestFrame() from inside an AnimationTimer instead. Only one stream may be active per Webcam at a time. Calling startStream() while one is already running throws.
- @p
OnFrameis a callback invoked with one Buffer argument per frame. - @p
Fpsis an optional double with the target frames per second. The default is 30.0. The rate is a soft cap, not a guarantee. - @p
Formatis an optional ImageIO format name. The default is png. - @r
Thisobject.
- @p
-
stopStream ()
Stops a push stream started with startStream() and waits briefly for the stream thread to exit. Safe to call when no stream is running.
- @r
Thisobject.
- @r
-
isStreaming ()
Returns whether a push stream is currently running.
- @r
Abool with true if a stream is active and false if not.
- @r
class: WebcamCapture
[32:21] static (extern: com.lehman.aussom.WebcamCapture) extends: object
Static entry point for webcam discovery.
Methods
-
getDefault ()
Gets the system default webcam. This function takes no options. The selected device is chosen by the webcam-capture library and the operating system.
- @r
AWebcam object, or null if no webcam is available.
- @r
-
getWebcams ()
Gets all webcams detected on the system. This function takes no options. Device discovery is handled by the webcam-capture library.
- @r
Alist of Webcam objects. The list is empty when no webcam is found.
- @r
-
getDefaultName ()
Gets the name of the system default webcam. This function takes no options. The selected device is chosen by the webcam-capture library and the operating system.
- @r
Astring with the webcam name, or null if no webcam is available.
- @r