Coder Social home page Coder Social logo

webcam.js's Introduction

Overview

webcam.js is a javascript library for web-camera handling

webcam.js is distributed under MIT license.

Functions

  • Open/Close the Web Camera
  • Support multiple-camera
  • Get snapshot image (Classical way)
  • Get snapshots continuously (Classical way)
  • Grab Frame (use new API ImageCapture :A new way to take a snapshot)
  • Take Photo (use new API ImageCapture API)

The status of ImageCapture API is now(11.27.2017) WORKING DRAFT.
But the experimental implementation is available on chrome 59+ etc.

Demo

Examples

Usage

#grabFrame

grabFrame() takes a snapshot of the live video being held in track, returning an ImageBitmap if successful. Wrapped W3C ImageCapture API.

var wcm = new WebCamera({
       videoTag: document.getElementById("video"),
       constraints: {
           video: {
               width: 640,
               height: 480,
           }
       }
   });

 wcm.startCamera();

 //grabFrame() takes a snapshot of the live video
 wcm.grabFrame().then(function (imageBitmap) {

 var canvas = document.getElementById("canvas");
 canvas.width = imageBitmap.width;
 canvas.height = imageBitmap.height;
 var ctx = canvas.getContext("2d");
 ctx.drawImage(imageBitmap, 0, 0);

});

#takePhoto

takePhoto() produces the result of a single exposure using the video capture device.Briefly, in the case of grabframe(), image data is subsampled in the process of image processing.In the case of takePhoto(),you may get an original image(not subsampled) from image sensor.

Wrapped W3C ImageCapture API.

var wcm = new WebCamera({
       videoTag: document.getElementById("video"),
       constraints: {
           video: {
               width: 640,
               height: 480,
           }
       }
   });

 wcm.startCamera();

 //take photo
 wcm.takePhoto()
    .then(function (blob) {
        return window.createImageBitmap(blob);
    })
    .then(function (imageBitmap) {

        var canvas = document.getElementById("canvas");
        canvas.width = imageBitmap.width;
        canvas.height = imageBitmap.height;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(imageBitmap, 0, 0);
    });

});

#repeated grabbing

If you call setOnSnapShotCallback(callbackFunc) , repeated grabbing is starting.

var wcm = new WebCamera({
       videoTag: document.getElementById("video"),
       constraints: {
           video: {
               width: 640,
               height: 480,
           }
       }
   });

 wcm.startCamera();

 //set continuous capturing callback with specfied size
wcm.setOnSnapShotCallback(function (imageBitmap) {
    canvas.width = imageBitmap.width;
    canvas.height = imageBitmap.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(imageBitmap, 0, 0);

},320,240);

Run on node.js

You can import library with npm.

Install

npm install webcam.js

Run demo

npm run ex00

Run exmaples

npm run ex01
npm run ex02
npm run ex03
npm run ex03
npm run ex04
npm run ex05

Run on browser

Download actual files

<script src="webcam.js"></script>

webcam.js's People

Contributors

riversun 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.