All Projects → GoogleChromeLabs → Imagecapture Polyfill

GoogleChromeLabs / Imagecapture Polyfill

Licence: apache-2.0
MediaStream ImageCapture polyfill. Take photos from the browser as easy as .takePhoto().then(processPhoto)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Imagecapture Polyfill

Ts Polyfill
Runtime polyfills for TypeScript libs, powered by core-js! 🔋 🔩
Stars: ✭ 122 (-18.67%)
Mutual labels:  polyfill
History.js
History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it wi…
Stars: ✭ 10,761 (+7074%)
Mutual labels:  polyfill
Mobilecameratemplate
A HTML5, JS, CSS Camera interface template. Feel free to use it in your next Computer Vision or AI project.
Stars: ✭ 145 (-3.33%)
Mutual labels:  camera
C4
Open IP cameras in IPv4
Stars: ✭ 123 (-18%)
Mutual labels:  camera
Kv Storage Polyfill
A polyfill for the kv-storage built-in module.
Stars: ✭ 130 (-13.33%)
Mutual labels:  polyfill
C Is For Camera
A 35mm camera, based on the Canonet G-III QL17 rangefinder, simulated in Python.
Stars: ✭ 138 (-8%)
Mutual labels:  camera
Balena Cam
Network Camera with Raspberry Pi and WebRTC. Tutorial:
Stars: ✭ 120 (-20%)
Mutual labels:  camera
Jeelizfacefilter
Javascript/WebGL lightweight face tracking library designed for augmented reality webcam filters. Features : multiple faces detection, rotation, mouth opening. Various integration examples are provided (Three.js, Babylon.js, FaceSwap, Canvas2D, CSS3D...).
Stars: ✭ 2,042 (+1261.33%)
Mutual labels:  camera
Fullscreencamera
A Full Screen Camera App written in Swift
Stars: ✭ 131 (-12.67%)
Mutual labels:  camera
React Af
Allows you to code using certain React.next features today! Perfect for component library maintainers.
Stars: ✭ 143 (-4.67%)
Mutual labels:  polyfill
Privacy Indicator App
🔔 Get the famous "Recording Indicators" feature of iOS14 to android. Get notified every time a third-party app or a service uses camera or microphone.
Stars: ✭ 124 (-17.33%)
Mutual labels:  camera
React Native Qrcode Scanner
A QR code scanner component for React Native.
Stars: ✭ 1,796 (+1097.33%)
Mutual labels:  camera
Imageprocessing
MicaSense RedEdge and Altum image processing tutorials
Stars: ✭ 139 (-7.33%)
Mutual labels:  camera
Document.scrollingelement
A polyfill for document.scrollingElement as defined in the CSSOM specification.
Stars: ✭ 122 (-18.67%)
Mutual labels:  polyfill
Pictureselectorlight
Picture Selector Library for Android or 图片选择器
Stars: ✭ 145 (-3.33%)
Mutual labels:  camera
Alexa Ip Cam
Use Alexa's Smart Home Skill API with standalone IP cameras without needing cloud service.
Stars: ✭ 121 (-19.33%)
Mutual labels:  camera
Wslivedemo
音视频,直播SDK,rtmp推流,录制视频,滤镜。百万用户,线上迭代半年,已经稳定。
Stars: ✭ 1,782 (+1088%)
Mutual labels:  camera
Ngx Webcam
A simple Angular webcam component / pure & minimal, no flash-fallback
Stars: ✭ 148 (-1.33%)
Mutual labels:  camera
Hybridcamera
Video and photo camera for iOS
Stars: ✭ 145 (-3.33%)
Mutual labels:  camera
Androidcamera
🔥🔥🔥自定义Android相机(仿抖音 TikTok),其中功能包括视频人脸识别贴纸,美颜,分段录制,视频裁剪,视频帧处理,获取视频关键帧,视频旋转,添加滤镜,添加水印,合成Gif到视频,文字转视频,图片转视频,音视频合成,音频变声处理,SoundTouch,Fmod音频处理。 Android camera(imitation Tik Tok), which includes video editor,audio editor,video face recognition stickers, segment recording,video cropping, video frame processing, get the first video frame, key frame, v…
Stars: ✭ 2,112 (+1308%)
Mutual labels:  camera

ImageCapture polyfill

Build Status Dependency Status devDependency Status

ImageCapture is a polyfill for the MediaStream Image Capture API.

Status

As of June 2017, the ImageCapture spec is relatively stable. Chrome supports the API starting with M59 (earlier versions require setting a flag) and Firefox has partial support behind a flag. See the ImageCapture browser support page for details.

Prior art

Prior to this API, in order to take a still picture from the device camera, two approaches have been used:

  1. Set the source of a <video> element to a stream obtained via navigator[.mediaDevices].getUserMedia, then use a 2D canvas context to drawImage from that video. The canvas can return a URL to be used as the src attribute of an <img> element, via .toDataURL('image/<format>'). (1, 2)
  2. Use the HTML Media Capture API, i.e. <input type="file" name="image" accept="image/*" capture>

Demo

The demo currently shows grabFrame() and takePhoto().

Quick start

yarn add image-capture

Or, with npm:

npm install --save image-capture

In your JS code:

let videoDevice;
let canvas = document.getElementById('canvas');
let photo = document.getElementById('photo');

navigator.mediaDevices.getUserMedia({video: true}).then(gotMedia).catch(failedToGetMedia);

function gotMedia(mediaStream) {
  // Extract video track.
  videoDevice = mediaStream.getVideoTracks()[0];
  // Check if this device supports a picture mode...
  let captureDevice = new ImageCapture(videoDevice);
  if (captureDevice) {
    captureDevice.takePhoto().then(processPhoto).catch(stopCamera);
    captureDevice.grabFrame().then(processFrame).catch(stopCamera);
  }
}

function processPhoto(blob) {
  photo.src = window.URL.createObjectURL(blob);
}

function processFrame(imageBitmap) {
  canvas.width = imageBitmap.width;
  canvas.height = imageBitmap.height;
  canvas.getContext('2d').drawImage(imageBitmap, 0, 0);
}

function stopCamera(error) {
  console.error(error);
  if (videoDevice) videoDevice.stop();  // turn off the camera
}

photo.addEventListener('load', function () {
  // After the image loads, discard the image object to release the memory
  window.URL.revokeObjectURL(this.src);
});

Methods

Start by constructing a new ImageCapture object:

let captureDevice;

navigator.mediaDevices.getUserMedia({video: true}).then(mediaStream => {
  captureDevice = new ImageCapture(mediaStream.getVideoTracks()[0]);
}).catch(...)

Please consult the spec for full detail on the methods.

constructor(videoStreamTrack)

Takes a video track and returns an ImageCapture object.

getPhotoCapabilities

TBD

setOptions

TBD

takePhoto

Capture the video stream into a Blob containing a single still image.

Returns a Promise that resolves to a Blob on success, or is rejected with DOMException on failure.

captureDevice.takePhoto().then(blob => {
  
}).catch(error => ...);

grabFrame

Gather data from the video stream into an ImageBitmap object. The width and height of the ImageBitmap object are derived from the constraints of the video stream track passed to the constructor.

Returns a Promise that resolves to an ImageBitmap on success, or is rejected with DOMException on failure.

captureDevice.grabFrame().then(imageBitmap => {
  
}).catch(error => ...);

Compatibility

The polyfill has been tested to work in current browsers:

  • Chrome 55+
  • Firefox 49+
  • Chrome 52+ for Android
  • Firefox 48+ for Android

For the widest compatibility, you can additionally load the WebRTC adapter. That will expand support to:

  • Chrome 53

For older browsers that don't support navigator.getUserMedia, you can additionally load Addy Osmani's shim with optional fallback to Flash - getUserMedia.js. Alternatively, the getUserMedia wrapper normalizes error handling and gives an error-first API with cross-browser support.

Development

yarn

yarn
yarn run dev

npm

npm install
npm run dev

To make your server accessible outside of localhost, run npm/yarn run lt.

Before committing, make sure you pass yarn/npm run lint without errors, and run yarn/npm run docs to generate the demo.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].