Giter VIP home page Giter VIP logo

node-webcam's Introduction

node-webcam

Cross platform webcam usage

Install

Linux

#Linux relies on fswebcam currently
#Tested on ubuntu

sudo apt-get install 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

//Available in nodejs

var NodeWebcam = require( "node-webcam" );


//Default options

var opts = {

    //Picture related

    width: 1280,

    height: 720,

    quality: 100,


    //Delay to take shot

    delay: 0,


    //Save shots in memory

    saveShots: true,


    // [jpeg, png] support varies
    // Webcam.OutputTypes

    output: "jpeg",


    //Which camera to use
    //Use Webcam.list() for results
    //false for default device

    device: false,


    // [location, buffer, base64]
    // Webcam.CallbackReturnTypes

    callbackReturn: "location",


    //Logging

    verbose: false

};


//Creates webcam instance

var Webcam = NodeWebcam.create( opts );


//Will automatically append location output type

Webcam.capture( "test_picture", function( err, data ) {} );


//Also available for quick use

NodeWebcam.capture( "test_picture", opts, function( err, data ) {

});


//Get list of cameras

Webcam.list( function( list ) {

    //Use another device

    var anotherCam = NodeWebcam.create( { device: list[ 0 ] } );

});

//Return type with base 64 image

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


#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

Classes

NodeWebcam

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.

//Default options defined in API usage

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!" );

});

Webcams

Base webcam class in which all other cameras inherit from

Webcam.constructor( Object options )

//Default options and basic usage

var opts = {

    width: 1280,

    height: 720,

    delay: 0,

    quality: 100,

    // [jpeg, png] support varies
    // Webcam.OutputTypes

    output: "jpeg",

    device: false,


    // [buffer, base64]
    // Webcam.CallbackReturnTypes

    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.

FSWebcam

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; //require( "node-webcam/webcams/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!

node-webcam's People

Contributors

chuckfairy avatar smihica avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.