Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
andreluisjunqueira authored Mar 28, 2019
2 parents 436a8f3 + 382ed90 commit b03b640
Show file tree
Hide file tree
Showing 7 changed files with 2,095 additions and 85 deletions.
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;
123 changes: 64 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@

![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:
```
Expand All @@ -53,73 +55,76 @@ project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../no
```
<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
2 changes: 1 addition & 1 deletion android/openCVLibrary310/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
android:versionCode="3100"
android:versionName="3.1.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
<!--<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />-->
</manifest>
24 changes: 24 additions & 0 deletions android/src/main/java/com/documentscanner/views/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.FrameLayout;

import com.documentscanner.R;
Expand Down Expand Up @@ -44,6 +46,24 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {

int action = MotionEventCompat.getActionMasked(event);

switch (action) {
case (MotionEvent.ACTION_UP):
this.focus();
case (MotionEvent.ACTION_DOWN):
case (MotionEvent.ACTION_MOVE):
case (MotionEvent.ACTION_CANCEL):
case (MotionEvent.ACTION_OUTSIDE):
return true;
default:
return super.onTouchEvent(event);
}
}

public void setDocumentAnimation(boolean animate){
view.setDocumentAnimation(animate);
}
Expand Down Expand Up @@ -91,4 +111,8 @@ public void setRemoveGrayScale(boolean grayscale) {
public void capture() {
view.capture();
}

private void focus() {
view.focus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public void capture(){
this.requestManualPicture();
}

public void focus(){
this.requestManualFocus();
}

public void setManualOnly( boolean manualOnly){
this.manualCapture = manualOnly;
}
Expand Down Expand Up @@ -579,6 +583,24 @@ public void run() {
});
}

public boolean requestManualFocus(){
PackageManager pm = mActivity.getPackageManager();
if(safeToTakePicture){
safeToTakePicture = false;
if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)) {
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
Log.d(TAG,"Manual focus => " + success);
}
});
}
safeToTakePicture = true;
return true;
}
return false;
}

public boolean requestManualPicture(){
this.blinkScreenAndShutterSound();
this.waitSpinnerVisible();
Expand Down
Loading

0 comments on commit b03b640

Please sign in to comment.