Cross platform webcam usage
#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 relies on imagesnap
#Repo https://github.com/rharder/imagesnap
#Avaliable through brew
brew install imagesnap
Standalone exe included. See src/bindings/CommandCam
//Available in nodejsvarNodeWebcam=require("node-webcam");//Default optionsvaropts={//Picture relatedwidth: 1280,height: 720,quality: 100,// Number of frames to capture// More the frames, longer it takes to capture// Use higher framerate for quality. Ex: 60frames: 60,//Delay in seconds to take shot//if the platform supports miliseconds//use a float (0.1)//Currently only on windowsdelay: 0,//Save shots in memorysaveShots: true,// [jpeg, png] support varies// Webcam.OutputTypesoutput: "jpeg",//Which camera to use//Use Webcam.list() for results//false for default devicedevice: false,// [location, buffer, base64]// Webcam.CallbackReturnTypescallbackReturn: "location",//Loggingverbose: false};//Creates webcam instancevarWebcam=NodeWebcam.create(opts);//Will automatically append location output typeWebcam.capture("test_picture",function(err,data){});//Also available for quick useNodeWebcam.capture("test_picture",opts,function(err,data){});//Get list of camerasWebcam.list(function(list){//Use another devicevaranotherCam=NodeWebcam.create({device: list[0]});});//Return type with base 64 imagevaropts={callbackReturn: "base64"};NodeWebcam.capture("test_picture",opts,function(err,data){varimage="<img src='"+data+"'>";});#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
# install yuidoc and run
./bin/generate_doc.sh
Main require used. Also has helper functions just for you.
Main factory creation of a webcam for use. Uses NodeWebcam.Factory to create.
//Default options defined in API usagevarNodeWebcam=require("node-webcam");varWebcam=NodeWebcam.create({});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
//Default options and basic usagevaropts={width: 1280,height: 720,delay: 0,quality: 100,// [jpeg, png] support varies// Webcam.OutputTypesoutput: "jpeg",device: false,// [buffer, base64]// Webcam.CallbackReturnTypescallbackReturn: "location",verbose: false}varcam=newWebcam(opts);Reset data and memory of past shots
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.
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.
varNodeWebcam=require("node-webcam");varFSWebcam=NodeWebcam.FSWebcam;//require( "node-webcam/webcams/FSWebcam" );varopts={};varcam=newFSWebcam(opts);- Video capture functionality
- Battle testing
- What do you want to see? Leave an issue on the github page!