Module: camera

Module to access camera hardware on the host.

This implementation uses the webcam-capture package by Bartosz Firyn (SarXos), available from: https://github.com/sarxos/webcam-capture

Author:
  • Edward A. Lee
Source:

Methods

(static) Camera(name)

Construct an instance of an Camera object type. To capture an image from the default camera, you can do this:

    var cameras = require("cameras");
    var camera = new cameras.Camera();
    camera.open();
    var image = camera.snapshot();
    camera.close();
 
The image will be a binary object. This object can be sent to an output port displayed or otherwise further processed. To capture every image from the camera, you can do this:
    var cameras = require("cameras");
    var camera = new cameras.Camera();
    camera.on('image', function(image) { ... handle the image ... });
    camera.open();
    ...
    camera.close();
 
An instance of this object type implements the following functions:
  • close(): Close the camera.
  • getViewSize(): Return the current view size for this camera as a JSON string, as in {"width":176, "height":144}.
  • on(event, handler): Specify an event handler for the camera.
  • open(): Open the camera.
  • setViewSize(size): Set the current view size for this camera. The argument can either be a JSON string or an object with a width and height field, as in for example {"width":176, "height":144}.
  • snapshot(): Return the last image recorded by the camera.
  • viewSizes(): Return an array of view sizes supported by this camera, each given as a JSON string of the form '{"width":176, "height":144}', for example.
An instance of this object emits the following events:
  • "opened": The camera has been opened.
  • "image": A new image has been obtained.
  • "closed": The camera has been closed.

Parameters:
Name Type Description
name

The camera name, or null to use the default camera.

Source:

(static) cameras()

Return an array of camera names for cameras currently available on the current host. This array includes a special name "default camera", which represents the system default camera, if there is one.

Source:
Returns:

An array of names, or null if there are no cameras.

(static) defaultCamera()

Return the name of the default camera on the current host, or null if there is none.

Source:
Returns:

A camera name.