Skip to content

A nice utility for accessing the user's native webcam through javascript

License

Notifications You must be signed in to change notification settings

ryhan/CameraKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CameraKit

A slightly nicer way to access a webcam from within a browser. Built by Ryhan.

Start by intializing a new instance of CameraKit.

This should cause the browser to prompt the user about allowing access to the camera.

// Set up and request access to the camera
var camera = new CameraKit();

You can optionally supply an onerror function that catches when

  • the browser does not support native webcam access, or
  • the user chose to deny webcam access
var camera = new CameraKit({
  onerror: function(){ /* Do something when we couldn't access the camera */ }
});

Get the current image from the camera

Call getImage() on your CameraKit object. You'll be returned a png encoded as a data url.

// Get a png encoded as a data url...
var new_image = camera.getImage();

// ... and set it as the source of your <img /> element.
some_image_element.setAttribute('src', new_image);

Perform some operation on the image from the camera

Call getData() on your CameraKit object. You'll be returned an ImageData object containing height, width, and an array of arrays containing rgba values.

About

A nice utility for accessing the user's native webcam through javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published