• Stars
    star
    240
  • Rank 168,229 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 8 months ago

Reviews

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

Repository Details

javascript access webcam stream and take photo

Webcam Easy JS

This is a javascript library for accessing webcam stream and taking photos.

You can easily add it as a module to your own app.

  • Streaming webcam on desktop computer or mobile
  • Switch back or front cameras on mobile
  • Take pictures and be able to download.

Live Demo

https://bensonruan.com/how-to-access-webcam-and-take-photo-with-javascript/

webcam-easy-demo

Installation

Use Git Clone

git https://github.com/bensonruan/webcam-easy.git

OR Use NPM

NPM

npm install webcam-easy

Usage

1. Include script tag in html

<script type="text/javascript" src="https://unpkg.com/webcam-easy/dist/webcam-easy.min.js"></script>
or Import into javascript
import Webcam from 'webcam-easy';

2. Place elements in HTML

<video id="webcam" autoplay playsinline width="640" height="480"></video>
<canvas id="canvas" class="d-none"></canvas>
<audio id="snapSound" src="audio/snap.wav" preload = "auto"></audio>

3. Call constructor in javascript

const webcamElement = document.getElementById('webcam');
const canvasElement = document.getElementById('canvas');
const snapSoundElement = document.getElementById('snapSound');
const webcam = new Webcam(webcamElement, 'user', canvasElement, snapSoundElement);

4. Start Webcam

webcam.start()
   .then(result =>{
      console.log("webcam started");
   })
   .catch(err => {
       console.log(err);
   });

5. Take Photo

var picture = webcam.snap();

6. Stop Webcam

webcam.stop();

Functions

  • start(startStream) : start streaming webcam

    • get permission from user
    • get all video input devices info
    • select camera based on facingMode
    • start stream

    startStream is optional parameter, default value is true

  • stop() : stop streaming webcam

  • stream() : start streaming webcam to video element

  • snap() : take photo from webcam

  • flip() : change Facing mode and selected camera

Properties

  • facingMode : 'user' or 'enviroment'
  • webcamList : all available camera device
  • webcamCount : number of available camera device

More Repositories

1

Chrome-Web-Speech-API

Chrome Web Speech API
JavaScript
113
star
2

Face-Mask

Real time webcam face detection, protect yourself from COVID19 with a virtual mask
JavaScript
77
star
3

Tesseract-OCR

Tesseract.js OCR
HTML
59
star
4

Hand-Written-Digit-Recognition

Hand Written Digit Recognition
JavaScript
59
star
5

Selfie-Anywhere

Selfie Anywhere
JavaScript
50
star
6

Face-Detection

Face detection from webcam in browser using javascript library face-api.js
HTML
34
star
7

Sentiment-Analysis

Twitter Sentiment Analysis
PHP
32
star
8

Virtual-Glasses-Try-on

Implementation of virtual glasses try on using Three.js + TensorFlow.js + Facemesh model. Experience the cutting-edge fusion of computer vision and augmented reality, allowing users to try on various virtual glasses in real-time.
JavaScript
26
star
9

Neural-Style-Transfer

Neural Style Transfer
HTML
21
star
10

Motion-Detection-Virtual-Drums

Motion Detection - Have fun with the virtual drums
JavaScript
20
star
11

Speech-Command

Speech Command Recognizer using tensorflowjs
JavaScript
16
star
12

Color-Tracking

Color Tracking with tracking.js
JavaScript
10
star
13

ReplyWithChatGPT

A WordPress plugin that integrate with OpenAI's ChatGPT API, use AI generated response to help you reply comments
PHP
6
star
14

Toxic-Comment-Classifier

Toxic-Comment-Classifier
JavaScript
4
star
15

Hand-Track

Magic Fire In Your Hand
CSS
4
star
16

Youtube-Sentiment-Analysis

Sentiment Analysis on YouTube comments, connect to YouTube API, fetch video comments, classify comments as positive, neutral and negative, and build a dashboard.
JavaScript
3
star
17

Ocrad.js

Ocrad.js - Harnessing the Power of Optical Character Recognition in JavaScript
JavaScript
2
star
18

QRCode.js

Demo to create dynamic QR codes with javascript library qrcode.js
HTML
1
star