Document scanner with border detection, perspective correction and custom crop/resize

Overview

react-native-document-scanner

Preview

iOS

iOS Preview

Android

Android Preview

Both Platform

Use version >=1.4.1 if you are using react-native 0.48+

$ yarn add https://github.com/AugustoPinheiro/react-native-document-scanner

$ react-native link react-native-document-scanner

Edit the info.plist file in XCode and add the following permission : NSCameraUsageDescription

Remember, this library uses your device camera, you can't run it on a simulator.

Android Only

If you do not have it already in your project, you must link openCV in your settings.gradle file

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-document-scanner/android/openCVLibrary310')

In android/app/src/main/AndroidManifest.xml

Change manifest header to avoid "Manifest merger error". After you add xmlns:tools="http://schemas.android.com/tools" should look like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.<yourAppName>" xmlns:tools="http://schemas.android.com/tools">

Add tools:replace="android:allowBackup" in <application tag. It should look like this:

<application tools:replace="android:allowBackup" android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="false" android:theme="@style/AppTheme">

Add Camera permissions request:

<uses-permission android:name="android.permission.CAMERA" />

Usage

import React, { Component } from "react";
import { View, Image } from "react-native";

import DocumentScanner from "react-native-document-scanner";

class YourComponent extends Component {
  render() {
    return (
      <View>
        <DocumentScanner
          useBase64
          saveInAppDocument={false}
          onPictureTaken={data =>
            this.setState({
              image: data.croppedImage,
              initialImage: data.initialImage,
              rectangleCoordinates: data.rectangleCoordinates
            })
          }
          overlayColor="rgba(255,130,0, 0.7)"
          enableTorch={false}
          brightness={0.3}
          saturation={1}
          contrast={1.1}
          quality={0.5}
          onRectangleDetect={({ stableCounter, lastDetectionType }) =>
            this.setState({ stableCounter, lastDetectionType })
          }
          detectionCountBeforeCapture={5}
          detectionRefreshRateInMS={50}
          onPermissionsDenied={() => console.log("Permissions Denied")}
        />
        <Image
          source={{ uri: `data:image/jpeg;base64,${this.state.image}` }}
          resizeMode="contain"
        />
      </View>
    );
  }
}

Properties

Prop Platform Default Type Description
overlayColor Both none string Color of the detected rectangle : rgba recommended
detectionCountBeforeCapture Both 5 integer Number of correct rectangle to detect before capture
detectionRefreshRateInMS iOS 50 integer Time between two rectangle detection attempt
enableTorch Both false bool Allows to active or deactivate flash during document detection
useFrontCam iOS false bool Allows you to switch between front and back camera
brightness iOS 0 float Increase or decrease camera brightness. Normal as default.
saturation iOS 1 float Increase or decrease camera saturation. Set 0 for black & white
contrast iOS 1 float Increase or decrease camera contrast. Normal as default
quality iOS 0.8 float Image compression. Reduces both image size and quality
useBase64 iOS false bool If base64 representation should be passed instead of image uri's
saveInAppDocument iOS false bool If should save in app document in case of not using base 64
captureMultiple iOS false bool Keeps the scanner on after a successful capture
onPermissionsDenied android null func Function to call when the Android permissions are denied

Manual capture

  • First get component ref
<DocumentScanner ref={ref => (this.scanner = ref)} />
  • Then call :
this.scanner.capture();

Each rectangle detection (iOS only)

Props Params Type Description
onRectangleDetect { stableCounter, lastDetectionType } object See below

The returned object includes the following keys :

  • stableCounter

Number of correctly formated rectangle found (this number triggers capture once it goes above detectionCountBeforeCapture)

  • lastDetectionType

Enum (0, 1 or 2) corresponding to the type of rectangle found

  1. Correctly formated rectangle
  2. Wrong perspective, bad angle
  3. Too far

Returned image

Prop Params Type Description
onPictureTaken data object Returns the captured image in an object { croppedImage: ('URI or BASE64 string'), initialImage: 'URI or BASE64 string', rectangleCoordinates: 'object of coordinates' }

Save in app document

If you want to use saveInAppDocument options, then don't forget to add those raws in .plist :

<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

Dependencies

Usage

import RNDocumentScanner from 'react-native-document-scanner'

render () {
  return (
    <View style={styles.container}>
      <RNDocumentScanner />
    </View>
  )
}

Credits

TODO

  • Support for landscape orientation
Comments
  • Steps to run the example?

    Steps to run the example?

    I tried running the example but I'm not able to. Here are the steps I used:

    • git clone
    • cd example
    • npm i
    • react-native run-android This throws an error - Unable to find a matching configuration of project :react-native-document-scanner

    I tried random things:

    • I tried yarn install but that failed with some error.

    Can you please provide the exact steps to run the example? I wasn't able to import this tool in my existing project maybe due to some linking issue I was getting RNPdfScanner not fond in UIManager so I'll just build the example and add my existing work into this. Any help to successfully execute the example will be much appreciated. Thanks! @AugustoPinheiro

    opened by AyushExel 6
  • NPM start script not working.

    NPM start script not working.

    error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class. Run CLI with --verbose flag for more details.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] start: `node node_modules/react-native/local-cli/cli.js start`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] start script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\nisha\AppData\Roaming\npm-cache\_logs\2021-07-12T17_32_53_945Z-debug.log
    
    opened by nishanthbhat07 5
  • Cant able to Run project

    Cant able to Run project

    Task :app:compileDebugJavaWithJavac FAILED

    C:\Users\Gowtham.C\Downloads\New folder (4)\RN-react-native-document-scanner-main\android\app\src\main\java\com\example\MainApplication.java:7: error: package com.ubidreams.RNDocumentScanner does not exist import com.ubidreams.RNDocumentScanner.RNDocumentScannerPackage; ^ C:\Users\Gowtham.C\Downloads\New folder (4)\RN-react-native-document-scanner-main\android\app\src\main\java\com\example\MainApplication.java:30: error: cannot find symbol new RNDocumentScannerPackage(), ^ symbol: class RNDocumentScannerPackage 2 errors

    FAILURE: Build failed with an exception.

    opened by gowtham171 3
  • Package not available

    Package not available

    Hi,

    Thanks for posting this. However, it looks like the original package for performing the scan is in a parent directory.

    "react-native-document-scanner": "../",
    

    Would you mind pushing the parent directory too; otherwise this does not work.

    Thank You.

    opened by prasunsrivastava 2
  • Package not included

    Package not included

    Hi,

    It looks like the plugin is in a parent directory "../" and so the app cannot be installed.

    I'm very interested in using this package would you mind please sharing the content of the RN-ract-native-document-scanner from the parent dir?

    opened by ByronDev121 2
  • npm install react-native-document-scanner is not working

    npm install react-native-document-scanner is not working

    When I'm trying to execute npm install react-native-document-scanner it showing error as like below Screenshot 2021-09-17 at 5 01 45 PM

    I had tried by removing node modules but then also installation in not possible. Could you help me to solve this issue ?

    opened by emanu7478 1
  • Error Installing Library

    Error Installing Library

    I am trying to use and test your library, looks amazing, but seems like is not possible to get it installed on my project:

    on other closet issues, you mentioned we have to run: react-native install react-native-document-scanner and then follow installation steps.

    but when I do that, instead to install your library, it's installing this one: https://github.com/Michaelvilleneuve/react-native-document-scanner

    I also tried installing using react-native install RN-react-native-document-scanner but I got this error: image

    Please, help me, how I should install your library?

    Thanks

    opened by sleeviin 0
  • Only Error , No build successful !!!

    Only Error , No build successful !!!

    I tried many packages of document scanners but have not found a single one helpful for android. It will take you to only errors, build failed anyhow overcome build successful then it will not run on android, these should be maintained or closed. Otherwise, people have to waste time on these packages.

    opened by joy-mollick 0
  • Not able to install react-native-document-scanner

    Not able to install react-native-document-scanner

    Hi, I want to try this package. Facing the below error. My Current React-Native version is 0.70.5. Request you to please provide the solution. How can I run the example? In package.json it is pointing react-native-document-scanner to "../". Could you please guide?

    Could not resolve dependency: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: [email protected] npm ERR! node_modules/react-native npm ERR! react-native@"0.70.5" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react-native@"0.49.3" from [email protected] npm ERR! node_modules/react-native-document-scanner npm ERR! react-native-document-scanner@"https://github.com/AugustoPinheiro/react-native-document-scanner" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/bhushanlunkad/.npm/eresolve-report.txt for a full report.

    npm ERR! A complete log of this run can be found in: npm ERR! /Users/bhushanlunkad/.npm/_logs/2022-11-10T14_43_45_176Z-debug-0.log

    opened by ibhushanlunkad 0
  • Could not find org.piwik.sdk:piwik-sdk:0.0.4

    Could not find org.piwik.sdk:piwik-sdk:0.0.4

    Could not determine the dependencies of task ':react-native-document-scanner:compileDebugAidl'.

    Could not resolve all task dependencies for configuration ':react-native-document-scanner:debugCompileClasspath'. Could not find org.piwik.sdk:piwik-sdk:0.0.4. Required by: project :react-native-document-scanner Could not find us.feras.mdv:markdownview:1.1.0. Required by: project :react-native-document-scanner

    opened by mopilo 0
Owner
Augusto Pinheiro
CTO & Founder da @fluketmc acordo todos os dias brigando por um mercado mais justo. Para mim, tecnologia não é apenas meu trabalho, é minha paixão! 😊
Augusto Pinheiro
A cross-platform Mod for the popular Minecraft project, where the border always has a radius equal to the player's current experience level.

Level = Border A cross-platform Mod for the popular Minecraft project, where the border always has a radius equal to the player's current experience l

Jakob K 14 Nov 22, 2022
Undo Rotate Crop Save

URCS_app Undo Rotate Crop Save The following project has these functionalities: Has 2 windows namely HOME and EDIT(fragments of MainActivity) HOME win

Utkarsh Sharma 1 Jan 23, 2022
ReDoSHunter: A Combined Static and Dynamic Approach for Regular Expression DoS Detection

ReDoSHunter ReDoSHunter is a combined static and dynamic approach for regular expression DoS detection. LATEST NOTE (updated at 2021.09.13): ReDoSHunt

Yeting Li 43 Dec 23, 2022
Word wrapping program created using Java and Scanner imports.

WordWrap Word wrapping program created using Java and Scanner imports. The program begins by asking the user to input a number for line width. This re

Nikhil Khanna 1 Jan 31, 2022
log4j-scanner is a project derived from other members of the open-source community by CISA's Rapid Action Force team to help organizations identify potentially vulnerable web services affected by the log4j vulnerabilities.

Log4j Scanner This repository provides a scanning solution for the log4j Remote Code Execution vulnerabilities (CVE-2021-44228 & CVE-2021-45046). The

Cybersecurity and Infrastructure Security Agency 1.3k Dec 22, 2022
Log4j2Scan - Log4j2 RCE Passive Scanner plugin for BurpSuite

Log4j2Scan This tool is only for learning, research and self-examination. It should not be used for illegal purposes. All risks arising from the use o

Whwlsfb 439 Jan 6, 2023
Dynamic detection of likely invariants

This is the distribution of the Daikon invariant detector, Daikon version 5.8.11, released November 2, 2021. If you are working with a Daikon distrib

null 159 Dec 28, 2022
On-device wake word detection powered by deep learning.

Porcupine Made in Vancouver, Canada by Picovoice Porcupine is a highly-accurate and lightweight wake word engine. It enables building always-listening

Picovoice 2.8k Jan 7, 2023
An open-source, free, scanner for exotic armour in Hypixel Skyblock

TheExoticsMod An open-source, free, scanner for exotic armour in Hypixel Skyblock! Searches friendslists, the auction house, and inventories to find e

null 4 Dec 26, 2022
Official React Native client for FingerprintJS PRO. 100% accurate device identification for fraud detection.

FingerprintJS PRO React Native Official React Native module for 100% accurate device identification, created for the FingerprintJS Pro Server API. Thi

FingerprintJS 26 Nov 22, 2022
BinAbsInspector: Vulnerability Scanner for Binaries

What is BinAbsInspector? BinAbsInspector (Binary Abstract Inspector) is a static analyzer for automated reverse engineering and scanning vulnerabiliti

null 1.3k Jan 4, 2023
The Google code scanner API provides a complete solution for scanning codes without requiring your app to request camera permission.

Android Google Code Scanner The Google code scanner API provides a complete solution for scanning codes without requiring your app to request camera p

Prabhakar Thota 7 Nov 23, 2022
BungeeCord/Spigot plugin that fixes Multi-world detection by simulating mod presence on the server side

Companion for map mods Unofficial BungeeCord and Spigot (Paper) companion plugin for Xaero's Minimap (and their World Map), JourneyMap and VoxelMap. T

Artur Khusainov 3 Sep 18, 2022
Plugin for Spigot, PaperMC, BungeeCord and Velocity to create custom MOTDs, playercount message and playercount hover with priorities and conditions.

AdvancedServerList AdvancedServerList is a server and proxy plugin that allows you to create custom MOTDs and more in your server list with priority a

Andre_601 19 Dec 14, 2022
Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

AddressBook-SpringBoot-API Simple Springboot API for addressBook with redis cache. Supports all REST controllers and have custom error handling for ev

Shirish Saxena 1 Jan 21, 2022
Customizable calendar with animations and ability to select a day, a week, a month or a custom range

?? RangeCalendarView A customizable, easy-to-use calendar with range selection Screenshots Getting started This library is available on Maven Central,

Oleg Khmaruk 10 May 20, 2022
Melnica Server is a custom basic Servlet Container application which depends on Socket Programming.

Melnica Server Melnica Server is a custom basic Servlet Container application which depends on Socket Programming. The Description of Project Melnica

Batuhan Düzgün 18 Jun 26, 2022
This is a simple realization of custom messages pre/post processing in spring-boot HTTP/Stream requests & responses

spring-boot-custom-message-converting-instances This is a simple realization of custom messages converting in spring-boot HTTP requests and responses.

Innopolis University Java Team 1 Jul 22, 2022
This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS AppConfig values when injecting config properties with @ConfigProperty.

Using AWS AppConfig in a custom MicroProfile ConfigSource This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS A

AWS Samples 8 May 19, 2022