npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@axa-fr/slight-capture

v0.13.2

Published

Pure vanilla javascript library to capture a document image from webcam for web application. Tested on Chrome, Firefox, Safari.

Downloads

16

Readme

Slight Capture

Continuous Integration Quality Gate Reliability Security Code Coverage Twitter

About

Simple vanilla JS library to capture a clean image and light from documents from a webcam. It use Opencv.js under the hood. The usage is easy for user. Your data is lighter and cleaner for future OCR in your backend system.

Online Storybook Demo: https://wonderful-forest-0a9f5b103.3.azurestaticapps.net/

Get Started npm version

npm install @axa-fr/slight-capture --save

# To install in your public folder a light version of opencv.js
node ./node_modules/@axa-fr/slight-capture/bin/copy-opencv.mjs public

WARNING : To keep opencv.js up to date. You may setup a postinstall script in your package.json file to update it at each npm install. For example :

  "scripts": {
    ...
    "postinstall": "node ./node_modules/@axa-fr/slight-capture/bin/copy-opencv.mjs public"
  },

The sample bellow use react, but the library work with vanilla JS with any framework of your choice.

import React, {useEffect, useState} from "react";
import sligthCaptureFactory, {toBase64Async} from "@axa-fr/slight-capture";

const sligthCapture = sligthCaptureFactory();

export const SlightCaptureVideo = () => {
    
    const [state, setState] = useState({
        isLoading: false,
        url: null,
    });

    useEffect(() => {
        sligthCapture.initAsync('opencv.js');
    });

    const onCapture = async (file) => {
        const convertedFile = await toBase64Async(file);
        setState({...state, url: convertedFile});
    }

    const onChange = async event => {
        event.preventDefault();
        let file = event.target.files[0];
        if (!file) return;
        setState({...state, isLoading: true});
        const video = await sligthCapture.loadVideoAsync()(file, onCapture);
        setState({...state, isLoading: false});
        video.start();
    }

    if (state.isLoading) {
        return (<p>Loading</p>);
    }

    return (
        <form>
            <h1>Slight Capture</h1>
            <input type="file" onChange={onChange} multiple={true}/>
            <div>
                {state.url &&
                    <img style={{"maxWidth": "800px"}} src={state.url} alt="image found"/>
                }
            </div>
        </form>
    )

};

Texts can be override by passing a translation object to the initAsync method.

const translations = {
    'sc-modal__video-title' : 'Positionner 5 secondes votre document dans le cadre',
    'sc-modal__video-invert-camera' : "Inverser caméra",
    'sc-modal__video-message-too-dark' : "Image trop sombre",
    'sc-modal__video-quit' : "X",
    'sc-modal__confirm-loading' : "Traitement en cours...",
    'sc-modal__confirm-title':"Est-ce que tous les champs sont parfaitement lisibles ?",
    'sc-modal__confirm-button--ko':"Non",
    'sc-modal__confirm-button--ok':"Oui",
    'sc-modal__error-title': "Une erreur est survenue",
    'sc-modal__error-button--restart': "Recommencer",
    'sc-modal__error-button--quit': "Quitter",
    'sc-modal__video-message-too-white': "Image trop claire",
};


const onChange = async event => {
    // ...
    const properties = {
        translations,
        enableDefaultCss: false,
    };
    const video = await sligthCapture.loadVideoAsync()(file, onCapture, properties);
    // ...
}

All properties with default values :

const properties = {
    translations: texts,
    enableDefaultCss: true,
    outputImageQuality: 0.6,
    outputImageMimeType: 'image/jpeg',
    waitNumberOfSecond: 3,
    thresholdTooWhite: 1.15,
    thresholdTooDark: 2.5,
    video: {
        // lower resolution are speeder
        width: {ideal: 1600},
        height: {ideal: 1600},
        facingMode: {
            // "environment" for back webcam in priority else "face" for front webcam 
            ideal: 'environment' // 'face'
        },
    }
}

You can customize the css by passing properties.enableDefaultCss: false to take the control of the css. css use BEM (Block Element Modifier) convention.


/* CSS to customize SlightCapture 
   const video = await sligthCapture.loadVideoAsync()(file: file, onCaptureCallback: onCapture, enableDefaultCss: false);
   disable default inline css by passing enableDefaultCss: false to take the control of the css 
*/
.sc-modal {
  position: fixed;
  z-index: 10000000;
  padding-top: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  overflow: auto;
  background-color: white;
  text-align:center;
}

.sc-modal__video-title {
  padding-left: 0.5em;
  padding-right: 0.5em;
}

.sc-modal__video-invert-camera {
  padding: 0.5em;
  font-size: 1em;
  margin: 1em;
  position:absolute;
  background-color:#a8a8a88f;
}

.sc-modal__video-quit {
  padding: 0.3em;
  font-size: 1em;
  margin: 1em;
  position:absolute; 
  top: 0; 
  right: 0;
}

.sc-modal__video-video {
  display: inline;
  height: 80vh;
}

.sc-modal__video-container{
    position: absolute;
    z-index: 10000000;
    padding-top: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    background-color: white;
    text-align:center;
}

.sc-modal__confirm-container {
  position: absolute;
  z-index: 100000000;
  padding-top: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  overflow: auto;
  background-color: white;
  text-align:center;
}

.sc-modal__confirm-loading {
  
}

.sc-modal__confirm-title {
  
}

.sc-modal__confirm-image {
  max-width: 800px;
  width: 100%;
}

.sc-modal__confirm-button-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.sc-modal__confirm-button {
  padding: 0.5em;
  font-size: 2em;
  margin: 1em;
}



.sc-modal__error-container {
    position: absolute;
    z-index: 100000000;
    padding-top: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100vh;
    overflow: auto;
    background-color: white;
    text-align:center;
}

.sc-modal__error-title {

}

.sc-modal__error-button-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.sc-modal__error-button {
    padding: 0.5em;
    font-size: 2em;
    margin: 1em;
}


Contribute