Skip to content

Commit

Permalink
added new Anyline functions
Browse files Browse the repository at this point in the history
added new Document Ratio configs
  • Loading branch information
Jonas committed Dec 4, 2017
1 parent 4d5312f commit 5c5ba7f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 35 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ If you want to get detailed information on the config JSON, go to our[`documenta
#### Callbacks

```
AnylineOCR.setupScanViewWithConfigJson(
AnylineOCR.setup(
JSON.stringify(config),
“ANALOG_METER”,
this.onResult,
Expand All @@ -142,7 +142,7 @@ openAnyline = async () => {
...
try {
const result = await AnylineOCR.setupScanViewWithConfigJsonPromise(JSON.stringify(config), “ANALOG_METER”);
const result = await AnylineOCR.setupPromise(JSON.stringify(config), “ANALOG_METER”);
} catch(error) {
console.error(error);
}
Expand All @@ -151,6 +151,18 @@ openAnyline = async () => {
}
```

##### Deprecated
```
AnylineOCR.setupScanViewWithConfigJson(
JSON.stringify(config),
“ANALOG_METER”,
this.onResult,
this.onError
);
```



### 7. Add custom TrainData to the OCR Module
If you want to add you custom traindata, you have to copy it into the native project folder.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public String getName() {
return REACT_CLASS;
}

// Deprecated
@ReactMethod
public void setupScanViewWithConfigJson(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
onResultCallback = onResultReact;
Expand All @@ -79,7 +80,17 @@ public void setupScanViewWithConfigJson(String config, String scanMode, Callback
}

@ReactMethod
public void setupScanViewWithConfigJsonPromise(String config, String scanMode, final Promise promise) {
public void setup(String config, String scanMode, Callback onResultReact, Callback onErrorReact) {
onResultCallback = onResultReact;
onErrorCallback = onErrorReact;
this.returnMethod = "callback";
this.config = config;

routeScanMode(scanMode);
}

@ReactMethod
public void setupPromise(String config, String scanMode, final Promise promise) {
this.promise = promise;
this.returnMethod = "promise";
this.config = config;
Expand Down
35 changes: 24 additions & 11 deletions android/src/main/java/com/anyline/reactnative/DocumentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class DocumentActivity extends AnylineBaseActivity implements CameraOpenL
private Double maxDocumentOutputResolutionWidth = null;
private Double maxDocumentOutputResolutionHeight = null;

private ArrayList<Double> ratios = null;
private Double ratioDeviation = null;

private android.os.Handler handler = new android.os.Handler();

// takes care of fading the error message out after some time with no error reported from the SDK
Expand Down Expand Up @@ -103,26 +106,36 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

//get the destination resolution
// get Document specific Configs
if (jsonObject.has("document")) {
try {
this.quality = jsonObject.getJSONObject("document").getInt("quality");
this.maxDocumentOutputResolutionWidth = jsonObject.getJSONObject("document").getJSONObject("maxOutputResolution").getDouble("width");
this.maxDocumentOutputResolutionHeight = jsonObject.getJSONObject("document").getJSONObject("maxOutputResolution").getDouble("height");
JSONObject documentConfig = jsonObject.getJSONObject("document");
this.quality = documentConfig.getInt("quality");
this.maxDocumentOutputResolutionWidth = documentConfig.getJSONObject("maxOutputResolution").getDouble("width");
this.maxDocumentOutputResolutionHeight = documentConfig.getJSONObject("maxOutputResolution").getDouble("height");
this.ratios = getArrayListFromJsonArray(documentConfig.getJSONObject("ratio").getJSONArray("ratios"));
this.ratioDeviation = documentConfig.getJSONObject("ratio").getDouble("deviation");
} catch (JSONException e) {
finishWithError(e.getMessage());
return;
Log.e(TAG, e.getMessage());
}
}


documentScanView.setConfig(new AnylineViewConfig(this, jsonObject));
// Set a ratio you want the documents to be restricted to.
if(this.ratios != null){
documentScanView.setDocumentRatios(this.ratios.toArray(new Double[0]));
} else {
documentScanView.setDocumentRatios(DocumentScanView.DocumentRatio.DIN_AX_PORTRAIT.getRatio(), DocumentScanView.DocumentRatio.DIN_AX_LANDSCAPE.getRatio());
}

// Optional: Set a ratio you want the documents to be restricted to. default is set to DIN_AX
documentScanView.setDocumentRatios(DocumentScanView.DocumentRatio.DIN_AX_PORTRAIT.getRatio(), DocumentScanView.DocumentRatio.DIN_AX_LANDSCAPE.getRatio());
// Set a maximum deviation for the ratio. 0.15 is the default
if(this.ratios != null){
documentScanView.setMaxDocumentRatioDeviation(this.ratioDeviation);
} else {
documentScanView.setMaxDocumentRatioDeviation(0.15);
}

// Optional: Set a maximum deviation for the ratio. 0.15 is the default
documentScanView.setMaxDocumentRatioDeviation(0.15);
documentScanView.setConfig(new AnylineViewConfig(this, jsonObject));

// Set maximum output resolution
if (maxDocumentOutputResolutionWidth != null && maxDocumentOutputResolutionHeight != null) {
Expand Down
4 changes: 4 additions & 0 deletions example/Anyline/config/DocumentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export default {
"maxOutputResoultion" : {
"width" : 1920,
"height" : 1080
},
"ratio" : {
"rations" : ["0.707"],
"deviation" : "0.15"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/Anyline/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Anyline extends Component {


try {
const result = await AnylineOCR.setupScanViewWithConfigJsonPromise(JSON.stringify(config), type);
const result = await AnylineOCR.setupPromise(JSON.stringify(config), type);

console.log(result);
this.setState({buttonsDisabled: false});
Expand Down
13 changes: 11 additions & 2 deletions ios/AnylineDocumentScanViewController.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// AnylineDocumentScanViewController.h
// Anyline Cordova Example
// Anyline React-Native Example
//
// Created by Daniel Albertini on 23/06/16.
// Created by Jonas Laux
//
//

Expand All @@ -28,4 +28,13 @@
@property (nonatomic, assign) CGSize maxOutputResolution;


/**
* Maximum resolution of the output image
* @warning Parameter can only be changed when the scanning is not running.
*
* @since 3.19
*/
@property (nonatomic, assign) CGSize maxOutputResolution;


@end
21 changes: 6 additions & 15 deletions ios/AnylineDocumentScanViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ - (void)viewDidLoad {

AnylineDocumentModuleView *docModuleView = [[AnylineDocumentModuleView alloc] initWithFrame:self.view.bounds];
docModuleView.currentConfiguration = self.conf;

// Set max Output Resolution
if(!CGSizeEqualToSize(CGSizeZero, self.maxOutputResolution)){
docModuleView.maxOutputResolution = self.maxOutputResolution
}

NSError *error = nil;
BOOL success = [docModuleView setupWithLicenseKey:self.key delegate:self error:&error];

[docModuleView setDocumentRatios:@[ALDocumentRatioLetterPortrait]];

// Set max Output Resolution
if(!CGSizeEqualToSize(CGSizeZero, self.maxOutputResolution)){
docModuleView = self.maxOutputResolution
}

self.moduleView = docModuleView;

Expand All @@ -50,13 +51,6 @@ - (void)viewDidLoad {

}

//- (void)viewDidLayoutSubviews {
// [self updateWarningPosition:
// self.moduleView.cutoutRect.origin.y +
// self.moduleView.cutoutRect.size.height +
// self.moduleView.frame.origin.y +
// 90];
//}

#pragma mark - AnylineDocumentModuleDelegate method

Expand Down Expand Up @@ -153,8 +147,5 @@ - (void)showUserLabel:(ALDocumentError)error {
}];
}

//- (void)updateWarningPosition:(CGFloat)newPosition {
// self.warningView.center = CGPointMake(self.warningView.center.x, newPosition);
//}

@end
12 changes: 9 additions & 3 deletions ios/AnylineSDKPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ - (UIView *)view
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

// Deprecated
RCT_EXPORT_METHOD(setupScanViewWithConfigJson:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
self.onResultCallback = onResult;
self.onErrorCallback = onError;
self.returnMethod = @"callback";
self.config = config;
[self initView:scanMode];
}

RCT_EXPORT_METHOD(setup:(NSString *)config scanMode:(NSString *)scanMode onResultCallback:(RCTResponseSenderBlock)onResult onErrorCallback:(RCTResponseSenderBlock)onError) {
self.onResultCallback = onResult;
self.onErrorCallback = onError;
self.returnMethod = @"callback";
self.config = config;
[self initView:scanMode];
}

RCT_EXPORT_METHOD(setupScanViewWithConfigJsonPromise:(NSString *)config scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(setupPromise:(NSString *)config scanMode:(NSString *)scanMode resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
_resolveBlock = resolve;
_rejectBlock = reject;
self.returnMethod = @"promise";
self.config = config;
[self initView:scanMode];


}


Expand Down

0 comments on commit 5c5ba7f

Please sign in to comment.