Coder Social home page Coder Social logo

rn-scanner-android's Introduction

React Native Document Scanner for Android (Using OpenCV)

This library is (almost completely) based on this one. It just fixes the rotation of images and OpenCV library dependency.

Installation

yarn add https://github.com/oritec/rn-scanner-android.git

Then, open android/build.gradle and inside allprojects -> repositories:

allprojects {
    repositories {
        ...
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
        maven {
            url "http://dl.bintray.com/steveliles/maven"
        }
        maven {
            url "https://jitpack.io"
        }
    }
}

Open android/app/src/main/AndroidManifest.xml, and inside manifest tag include:

<manifest ...
    xmlns:tools="http://schemas.android.com/tools"
>

Inside application tag:

<application
    ...
    tools:replace="android:allowBackup"
>

Finally, open android/app/build.gradle and change compileSdkVersion xxx to:

compileSdkVersion 26

Bonus: install OpenCV library for Android

I found this excellent guide to install OpenCV on your Android Projects that works just fine with this library. Just follow every step of the guide but using OpenCV SDK version 3.1.0.

Usage

Simple Example

import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableNativeFeedback,
  Image,
} from 'react-native';

import {RNDocScanner} from 'rn-scanner-android';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      foto: null,
    };
  }

  onPressScan = async () => {
    try {
      const image = await RNDocScanner.getDocumentCrop(true);
      this.setState({foto: image});
    } catch (err) {
      console.log(err);
    }
  };

  render() {
    return (
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
        <Text style={{marginBottom: 20}}>Oritec Document Scanner</Text>
        <TouchableNativeFeedback
          onPress={this.onPressScan}
          background={TouchableNativeFeedback.SelectableBackground()}>
          <View
            style={{
              width: 250,
              backgroundColor: '#F7B44C',
              flexDirection: 'row',
              justifyContent: 'center',
              elevation: 3,
            }}>
            <Text style={{margin: 10, color: 'white', fontSize: 16}}>Scan</Text>
          </View>
        </TouchableNativeFeedback>
        <View style={{height: 250, marginTop: 50}}>
          {this.state.foto != null && (
            <Image
              source={{uri: this.state.foto}}
              style={{width: 250, height: 250}}
            />
          )}
        </View>
      </View>
    );
  }
}

rn-scanner-android's People

Contributors

oritec avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

rn-scanner-android's Issues

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.