Cross platform webcam usage
Install
Linux
#Linux relies on fswebcam currently
#ubuntu
sudo apt-get install fswebcam
#arch
#fswebcam requires a build from the AUR, it is not listed for installation on pacman/pamac
sudo pamac build fswebcam
Mac OSX
#Mac OSX relies on imagesnap
#Repo https://github.com/rharder/imagesnap
#Avaliable through brew
brew install imagesnap
Windows
Standalone exe included. See src/bindings/CommandCam
Usage
API Usage
var NodeWebcam = require( "node-webcam" );
var opts = {
width: 1280,
height: 720,
quality: 100,
frames: 60,
delay: 0,
saveShots: true,
output: "jpeg",
device: false,
callbackReturn: "location",
verbose: false
};
var Webcam = NodeWebcam.create( opts );
Webcam.capture( "test_picture", function( err, data ) {} );
NodeWebcam.capture( "test_picture", opts, function( err, data ) {
});
Webcam.list( function( list ) {
var anotherCam = NodeWebcam.create( { device: list[ 0 ] } );
});
var opts = {
callbackReturn: "base64"
};
NodeWebcam.capture( "test_picture", opts, function( err, data ) {
var image = "<img src='" + data + "'>";
});
Shell Usage
#Config opts
--width Picture width
--height Picture height
--delay Delay till shot
--quality Quality of image 0-100
--output Output type [png, jpg, bmp]
--verbose Verbose debugging
--help Usage help text
--version node-webcam version
--location Location to output webcam capture
--list list available camera devices
#Shorthand options
w: [ "--width" ],
h: [ "--height" ],
d: [ "--delay" ],
q: [ "--quality" ],
out: [ "--output" ],
h: [ "--help", true ],
v: [ "--version", true ],
l: [ "--location" ]
#node-webcam will auto output the file type at the end
node-webcam --w 500 --h 500 --d 2 --l picture # ./bin/node-webcam.js
Generated Documentation
# install yuidoc and run
./bin/generate_doc.sh
Classes
Main require used. Also has helper functions just for you.
NodeWebcam.create( Object options )
Main factory creation of a webcam for use. Uses NodeWebcam.Factory to create.
var NodeWebcam = require( "node-webcam" );
var Webcam = NodeWebcam.create({});
NodeWebcam.capture( String location, Object options, Function callback )
Quick helper for taking pictures via one function. Will return Webcam instance via NodeWebcam.create.
NodeWebcam.capture( "my_picture", {}, function( err, data ) {
if ( !err ) console.log( "Image created!" );
});
Base webcam class in which all other cameras inherit from
Webcam.constructor( Object options )
var opts = {
width: 1280,
height: 720,
delay: 0,
quality: 100,
output: "jpeg",
device: false,
callbackReturn: "location",
verbose: false
}
var cam = new Webcam( opts );
Webcam.clone()
Webcam.clear()
Reset data and memory of past shots
Webcam.capture( String location, Object options, Function callback( Error|Null, Buffer) )
First param of callback will be a possible error or null. Second will return the location of the image or null. The following functions will follow similarly. This function will auto append the output type if not specified in file name.
Webcam.getShot( Number shot, Function callback( Error|Null, Buffer) )
Webcam.getLastShot( Function callback )
Webcam.getBase64( Number|Buffer shot, Function callback( Error|Null, Buffer) )
Get base 64 of shot number or data already grabbed from FS.
Uses the fswebcam program. Available in linux (apt-get install fswebcam). Extra program addons provided in options.
var NodeWebcam = require( "node-webcam" );
var FSWebcam = NodeWebcam.FSWebcam;
var opts = {};
var cam = new FSWebcam( opts );
What's next?
- Video capture functionality
- Battle testing
- What do you want to see? Leave an issue on the github page!