• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript wrapper for HTML5 camera input

Camera.js

A simple wrapper around the HTML5 getUserMedia API, offering cross-browser access to the user's webcam video stream.

Usage

Upon initalization, the library asks the user for permission, sets up the necessary getUserMedia code and starts the stream. All parameters are optional, their default values are explained below.

The onFrame callback function is called each time there is a new frame to be processed, with respect to the fps option.

If you want the video stream to also be rendered in a <canvas> element, set the targetCanvas option to an element reference.

camera.init({
	width: 160, // default: 640
	height: 120, // default: 480
	fps: 30, // default: 30
	mirror: true,  // default: false
	targetCanvas: document.getElementById('webcam'), // default: null 

	onFrame: function(canvas) {
		// do something with image data found in the canvas argument
	},

	onSuccess: function() {
		// stream succesfully started, yay!
	},

	onError: function(error) {
		// something went wrong on initialization
	},

	onNotSupported: function() {
		// instruct the user to get a better browser
	}
});

To pause the video capture, call camera.pause(). To resume, call camera.start().

Live examples

ASCII Camera Predator Vision

Supported browsers

  • Chrome ≥ 21
  • Firefox ≥ 17 (requires media.navigator.enabled = true in about:config)
  • Opera ≥ 12

Author

Andrei Gheorghe

License

  • This code is licensed under the MIT License.