Skip to content

Commit

Permalink
changed Android Document Module Image location to Cache,
Browse files Browse the repository at this point in the history
changed License
  • Loading branch information
Jonas committed Nov 7, 2017
1 parent 2d2d9a5 commit 3bd24e9
Show file tree
Hide file tree
Showing 15 changed files with 2,231 additions and 44 deletions.
2,174 changes: 2,174 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ Callback -> Stringified JSON
}
```
More information about the simultaneous barcode scanning [here](https://documentation.anyline.io/toc/modules/overview.html#anyline-modules-simultaneous-barcode-scanning).

### onError Function
Callback -> String
- String errorMessage

## Images

Keep in mind, all the images are saved in the cache directory of the app. For performance reasons, we only provide the
path as string, so we don't have to transfer the whole image through the bridge. Please be aware, that you should not
use the images in the cache directory for persistent storage, but store the images in a location of your choice for persistence.

## License

See LICENSE file.
56 changes: 30 additions & 26 deletions android/src/main/java/com/anyline/reactnative/DocumentActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
Expand All @@ -20,13 +16,13 @@
import android.widget.TextView;
import android.widget.Toast;


import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

import at.nineyards.anyline.camera.AnylineViewConfig;
import at.nineyards.anyline.camera.CameraController;
Expand All @@ -35,6 +31,7 @@
import at.nineyards.anyline.modules.document.DocumentResult;
import at.nineyards.anyline.modules.document.DocumentResultListener;
import at.nineyards.anyline.modules.document.DocumentScanView;
import at.nineyards.anyline.util.TempFileUtil;

/**
* Example activity for the Anyline-Document-Detection-Module
Expand All @@ -51,7 +48,7 @@ public class DocumentActivity extends AnylineBaseActivity implements CameraOpenL
private FrameLayout errorMessageLayout;
private TextView errorMessage;
private long lastErrorRecieved = 0;
private int compressionRatio = 100;
private int quality = 100;

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

Expand Down Expand Up @@ -106,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) {
//get the destination resolution
if (jsonObject.has("document")) {
try {
this.compressionRatio = jsonObject.getJSONObject("document").getInt("compressionRatio");
this.quality = jsonObject.getJSONObject("document").getInt("quality");
} catch (JSONException e) {
finishWithError(e.getMessage());
return;
Expand Down Expand Up @@ -166,41 +163,46 @@ public void onResult(DocumentResult documentResult) {
* for example
*
*/
File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "ok");
File outDir = new File(getCacheDir(), "ok");
outDir.mkdir();
// change the file ending to png if you want a png
File outFile = new File(outDir, "transformed_" + System.currentTimeMillis() + ".jpg");
File outFileFull = new File(outDir, "full_" + System.currentTimeMillis() + ".jpg");
JSONObject jsonResult = new JSONObject();
try {
// convert the transformed image into a gray scaled image internally
// transformedImage.getGrayCvMat(false);
// get the transformed image as bitmap
// Bitmap bmp = transformedImage.getBitmap();
// save the image with quality 100 (only used for jpeg, ignored for png)
transformedImage.save(outFile, compressionRatio);
fullFrame.save(outFileFull, compressionRatio);
showToast(getString(getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + outFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
File imageFile = TempFileUtil.createTempFileCheckCache(DocumentActivity.this,
UUID.randomUUID().toString(), ".jpg");
transformedImage.save(imageFile, quality);
showToast(getString(getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + imageFile.getAbsolutePath());

// release the images
transformedImage.release();
fullFrame.release();
jsonResult.put("imagePath", imageFile.getAbsolutePath());


JSONObject jsonResult = new JSONObject();
try {
jsonResult.put("imagePath", outFile.getAbsolutePath());
jsonResult.put("fullImagePath", outFileFull.getAbsolutePath());
// Save the Full Frame Image
if (fullFrame != null) {
imageFile = TempFileUtil.createTempFileCheckCache(DocumentActivity.this,
UUID.randomUUID().toString(), ".jpg");
fullFrame.save(imageFile, quality);
jsonResult.put("fullImagePath", imageFile.getAbsolutePath());
}
// Put outline and conficence to result
jsonResult.put("outline", jsonForOutline(documentResult.getOutline()));
jsonResult.put("confidence", documentResult.getConfidence());

} catch (Exception jsonException) {
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException jsonException) {
//should not be possible
Log.e(TAG, "Error while putting image path to json.", jsonException);
}

// release the images
transformedImage.release();
fullFrame.release();

Boolean cancelOnResult = true;

JSONObject jsonObject;
Expand Down Expand Up @@ -251,11 +253,13 @@ public void onPictureProcessingFailure(DocumentScanView.DocumentError documentEr
AnylineImage image = documentScanView.getCurrentFullImage();

if (image != null) {
File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "error");
File outDir = new File(getCacheDir(), "error");
outDir.mkdir();
File outFile = new File(outDir, "" + System.currentTimeMillis() + documentError.name() + ".jpg");
try {
image.save(outFile, 100);
File imageFile = TempFileUtil.createTempFileCheckCache(DocumentActivity.this,
UUID.randomUUID().toString(), ".jpg");
image.save(imageFile, 100);
Log.d(TAG, "error image saved to " + outFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion example/Anyline/config/AutoEnergyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
options: {
"captureResolution": '1080p',
"cutout": {
"style": 'rect',
"style": 'CONTOUR_RECT',
"alignment": 'top',
"offset": {
'x': 0,
Expand Down
2 changes: 1 addition & 1 deletion example/Anyline/config/DocumentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default {
"blinkAnimationOnResult": true,
"cancelOnResult": true,
"document": {
"compressionRatio" : 90,
"quality" : 90,
}
}
}
2 changes: 1 addition & 1 deletion example/Anyline/config/EnergyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
'b1NxUUJTL3ZFS3VYUHhhCjNnanZnS285M3lrSjJKQjVBZjZiSkE9PQo=', options: {
captureResolution: '1080',
cutout: {
style: 'rect',
style: 'CONTOUR_RECT',
alignment: 'top',
offset: {
'x': 0,
Expand Down
2 changes: 0 additions & 2 deletions example/Anyline/ios/Anyline.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Anyline\"",
);
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down Expand Up @@ -1055,7 +1054,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/Anyline\"",
);
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down
2 changes: 1 addition & 1 deletion example/Anyline/ios/Anyline/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.17</string>
<string>3.18</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
6 changes: 3 additions & 3 deletions example/Anyline/src/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ export default function Overview({openAnyline, checkCameraPermissionAndOpen, dis

<Text style={styles.text}>ENERGY</Text>
<View style={styles.buttons}>
<Button style={styles.buttons} title={' Energy Auto Analog/Digital Meter Scanner'}
<Button style={styles.buttons} title={' Auto Analog/Digital Meter Scanner'}
color="#0099FF"
disabled={disabled}
onPress={() => {
platformPermissionCheck('AUTO_ANALOG_DIGITAL_METER')
}}/>
</View>
<View style={styles.buttons}>
<Button style={styles.buttons} title={' Energy Analog Meter Scanner'} color="#0099FF"
<Button style={styles.buttons} title={' Analog Meter Scanner'} color="#0099FF"
disabled={disabled}
onPress={() => {
platformPermissionCheck('ANALOG_METER')
}}/>
</View>
<View style={styles.buttons}>
<Button style={styles.buttons} title={' Energy Digital Meter Scanner'} color="#0099FF"
<Button style={styles.buttons} title={' Digital Meter Scanner'} color="#0099FF"
disabled={disabled}
onPress={() => {
platformPermissionCheck('DIGITAL_METER')
Expand Down
2 changes: 1 addition & 1 deletion ios/AnylineBarcodeScanViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)viewDidAppear:(BOOL)animated {
self.label.hidden = NO;


self.moduleView.videoView.barcodeDelegate = nil;
self.moduleView.captureDeviceManager.barcodeDelegate = nil;
}

#pragma mark - AnylineBarcodeModuleDelegate method
Expand Down
2 changes: 1 addition & 1 deletion ios/AnylineDocumentScanViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@interface AnylineDocumentScanViewController : AnylineBaseScanViewController

@property (nonatomic, assign) NSUInteger compressionRate;
@property (nonatomic, assign) NSUInteger quality;

@end
2 changes: 1 addition & 1 deletion ios/AnylineDocumentScanViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)anylineDocumentModuleView:(AnylineDocumentModuleView *)anylineDocumentMo

NSMutableDictionary *dictResult = [NSMutableDictionary dictionaryWithCapacity:4];

CGFloat dividedCompRate = (CGFloat) self.compressionRate/100;
CGFloat dividedCompRate = (CGFloat) self.quality/100;
NSString *imagePath = [self saveImageToFileSystem:transformedImage compressionQuality:dividedCompRate];
NSString *fullImagePath = [self saveImageToFileSystem:fullFrame compressionQuality:dividedCompRate];
NSString *outline = [self stringForOutline:corners];
Expand Down
6 changes: 3 additions & 3 deletions ios/AnylineEnergyScanViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ - (void)viewDidLoad {
energyModuleView.currentConfiguration = self.conf;

[energyModuleView setScanMode:self.scanMode error:nil];
[energyModuleView.videoView setBarcodeDelegate:self];
[energyModuleView.captureDeviceManager setBarcodeDelegate:self];

if (self.nativeBarcodeEnabled) {
energyModuleView.videoView.barcodeDelegate = self;
energyModuleView.captureDeviceManager.barcodeDelegate = self;
}

self.moduleView = energyModuleView;
Expand Down Expand Up @@ -143,7 +143,7 @@ - (void)anylineEnergyModuleView:(AnylineEnergyModuleView *)anylineEnergyModuleVi


#pragma mark - AnylineNativeBarcodeDelegate
- (void)anylineVideoView:(AnylineVideoView *)videoView
- (void)anylineVideoView:(AnylineVideoView *)captureDeviceManager
didFindBarcodeResult:(NSString *)scanResult
type:(NSString *)barcodeType {

Expand Down
4 changes: 2 additions & 2 deletions ios/AnylineSDKPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ - (AnylineBaseScanViewController *)ViewControllerFromScanMode:(NSString *)scanMo
NSDictionary *options = [self.jsonConfigDictionary valueForKey:@"options"];
if ([options valueForKey:@"document"]) {
NSDictionary *docConfig = [options valueForKey:@"document"];
docVC.compressionRate = [[docConfig valueForKey:@"compressionRatio"] integerValue];
docVC.quality = [[docConfig valueForKey:@"quality"] integerValue];
} else {
docVC.compressionRate = 100;
docVC.quality = 100;
}
return docVC;
} else if ([[scanMode uppercaseString] isEqualToString:[@"MRZ" uppercaseString]]) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.18.0",
"main": "index.js",
"description": "A Plugin for connecting Anyline with React-Native",
"license": "MIT",
"license": "SEE LICENSE IN LICENSE",
"repository": {
"type": "git",
"url": "https://github.com/Anyline/anyline-ocr-react-native-module"
Expand Down

0 comments on commit 3bd24e9

Please sign in to comment.