Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
53 changes: 0 additions & 53 deletions .gitignore

This file was deleted.

8 changes: 4 additions & 4 deletions DocumentScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DeviceEventEmitter, // android
NativeModules,
requireNativeComponent,
View
View,
} from 'react-native';

var iface = {
Expand Down Expand Up @@ -49,9 +49,9 @@ class Scanner extends PureComponent{
CameraManager.capture();
}

render(){
return <DocumentScanner {...this.props}/>
render() {
return <DocumentScanner {...this.props} />;
}
}

export default Scanner;
export default Scanner;
138 changes: 78 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,130 @@

![enter image description
here](https://media.giphy.com/media/KZBdm9gbGGRBlRZV1t/giphy.gif)

## React Native module to auto scan documents (Android only)


Live document detection library. Returns either a URI of the captured image, allowing you to easily store it or use it as you wish !
## React Native module to auto scan documents (Android only)

Live document detection library. Returns either a URI of the captured image, allowing you to easily store it or use it as you wish !

Features:
- Live detection
- Perspective correction and image crop
- Flash

- Live detection
- Perspective correction and image crop
- Flash

### Get started

`npm install --save react-native-documentscanner-android`

In MainApplication.java, add this Line `import com.documentscanner.DocumentScannerPackage;` at the top of file,
In MainApplication.java, add this Line `import com.documentscanner.DocumentScannerPackage;` at the top of file,

```java
```java
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new DocumentScannerPackage() <--- this line,
...
);
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new DocumentScannerPackage() <--- this line,
...
);
}
```

#### IMPORTANT - Go to folder app/settings.gradle and add

```java
include ':react-native-documentscanner-android'
project(':react-native-documentscanner-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-documentscanner-android/android')
```
#### Add this (don't forget)

#### Add this (don't forget)

```java
include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-documentscanner-android/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" />
```
#### Add this to android/app/build.gradle (dependencies section)
```
implementation project(':react-native-documentscanner-android')
```

### Usage

```javascript
import DocumentScanner from 'react-native-documentscanner-android';

class YourComponent extends Component {
render() {
return (
<View>
<DocumentScanner
onPictureTaken={data =>{
console.log(data.path)
}}
enableTorch={false}
detectionCountBeforeCapture={5}
/>
</View>
);
}
import DocumentScanner from 'react-native-documentscanner-android';

class YourComponent extends Component {
render() {
return (
<View>
<DocumentScanner
onPictureTaken={data => {
console.log(data.path);
}}
enableTorch={false}
detectionCountBeforeCapture={5}
/>
</View>
);
}
}

```




### Properties

|Props|Default|Type|Description
|--|--|--|--|
| manualOnly | false | `bool`|if true, auto-detect is disabled
| enableTorch | false | `bool`|Allows to active or deactivate flash during document detection
| detectionCountBeforeCapture | 15 |`number`|Number of correct rectangle to detect before capture document
| brightness | 10 | `number`|This property only work to enhance document at the save moment
| contrast | 1 | `number`|This property only work to enhance document at the save moment
| noGrayScale | false | `bool`|Currently this module saves pictures only in gray scale, this property adds the option to disable gray scale


| Props | Default | Type | Description |
| --------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------ |
| manualOnly | false | `bool` | if true, auto-detect is disabled |
| enableTorch | false | `bool` | Allows to active or deactivate flash during document detection |
| detectionCountBeforeCapture | 15 | `number` | Number of correct rectangle to detect before capture document |
| brightness | 10 | `number` | This property only work to enhance document at the save moment |
| contrast | 1 | `number` | This property only work to enhance document at the save moment |
| noGrayScale | false | `bool` | Currently this module saves pictures only in gray scale, this property adds the option to disable gray scale |

### Manual capture

- Get the component ref
- Get the component ref

`<DocumentScanner ref={(ref) => this.scanner = ref} />`

- Then
```javascript

```javascript
this.scanner.capture();
```

### Returned Image
| Prop | Params |Type| Description
|--|--|--|--|
| onPictureTaken | data | object | Returns an image in a object `{ path: ('imageUri')}`
| onProcessing | data | object |Returns an object `{processing: (true | false)}` to show is an image is processing yet

| Prop | Params | Type | Description |
| -------------- | ------ | ------ | -------------------------------------------------------------------------------------- |
| onPictureTaken | data | object | Returns an image in a object `{ path: ('imageUri')}` |
| onProcessing | data | object | Returns an object `{processing: (true | false)}` to show is an image is processing yet |

The images are saved in `Documents` folder.

#### Todo
- Pass overlay color dynamically
- Pass contrast and brightness to preview
- Use front cam
- Use base64


#### Todo

- Pass overlay color dynamically
- Pass contrast and brightness to preview
- Use front cam
- Use base64

## Contributors are welcome !!

Inspired in android project

Inspired in android project
- https://github.com/ctodobom/OpenNoteScanner
- https://github.com/Michaelvilleneuve/react-native-document-scanner
- https://github.com/Michaelvilleneuve/react-native-document-scanner
32 changes: 18 additions & 14 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,36 @@ buildscript {
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
splits {
abi {
reset()
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", 'x86_64'
}
}

// lintOptions {
// abortOnError false
// warning 'InvalidPackage'
// }
}

dependencies {
//compile project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-documentscanner-android/android')
compile project(':openCVLibrary310')
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.19.+"
compile 'com.google.zxing:core:3.0.1'
compile 'com.android.support:design:23.4.0'
compile 'org.piwik.sdk:piwik-sdk:0.0.4'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'us.feras.mdv:markdownview:1.1.0'
implementation project(':openCVLibrary310')
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.facebook.react:react-native:0.19.+"
implementation 'com.google.zxing:core:3.0.1'
implementation 'com.android.support:design:28.0.0'
implementation 'org.piwik.sdk:piwik-sdk:0.0.4'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'us.feras.mdv:markdownview:1.1.0'
}
Binary file added android/build/generated/mockable-android-14.jar
Binary file not shown.
Binary file added android/build/generated/mockable-android-23.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector android:height="24dp" android:viewportHeight="64.0"
android:viewportWidth="64.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#FF60FF60"
android:pathData="M0,0L0,60L0,64L4,64L64,64L64,60L4,60L4,0L0,0z"
android:strokeAlpha="1" android:strokeColor="#FF60FF60"
android:strokeLineJoin="round" android:strokeWidth="0"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF60FF60"
android:strokeColor="#FF007F00"
android:strokeWidth="0.5"
android:pathData="M9.4,10.5l4.77,-8.26C13.47,2.09 12.75,2 12,2c-2.4,0 -4.6,0.85 -6.32,2.25l3.66,6.35 0.06,-0.1zM21.54,9c-0.92,-2.92 -3.15,-5.26 -6,-6.34L11.88,9h9.66zM21.8,10h-7.49l0.29,0.5 4.76,8.25C21,16.97 22,14.61 22,12c0,-0.69 -0.07,-1.35 -0.2,-2zM8.54,12l-3.9,-6.75C3.01,7.03 2,9.39 2,12c0,0.69 0.07,1.35 0.2,2h7.49l-1.15,-2zM2.46,15c0.92,2.92 3.15,5.26 6,6.34L12.12,15L2.46,15zM13.73,15l-3.9,6.76c0.7,0.15 1.42,0.24 2.17,0.24 2.4,0 4.6,-0.85 6.32,-2.25l-3.66,-6.35 -0.93,1.6z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18,7l-1.41,-1.41 -6.34,6.34 1.41,1.41L18,7zm4.24,-1.41L11.66,16.17 7.48,12l-1.41,1.41L11.66,19l12,-12 -1.42,-1.41zM0.41,13.41L6,19l1.41,-1.41L1.83,12 0.41,13.41z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M20,19.59V8l-6,-6H6c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2H18c0.45,0 0.85,-0.15 1.19,-0.4l-4.43,-4.43c-0.8,0.52 -1.74,0.83 -2.76,0.83 -2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5c0,1.02 -0.31,1.96 -0.83,2.75L20,19.59zM9,13c0,1.66 1.34,3 3,3s3,-1.34 3,-3 -1.34,-3 -3,-3 -3,1.34 -3,3z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7,2v11h3v9l7,-12h-4l4,-8z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M11 17h2v-6h-2v6zm1-15C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zM11 9h2V7h-2v2z"/>
</vector>
Loading