Coder Social home page Coder Social logo

silky / webcam-easy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bensonruan/webcam-easy

0.0 0.0 0.0 760 KB

javascript access webcam stream and take photo

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

License: MIT License

JavaScript 100.00%

webcam-easy's Introduction

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

webcam-easy's People

Contributors

bensonruan avatar dependabot[bot] avatar rilla 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.