Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v5 beta branch #81

Merged
merged 9 commits into from
Apr 3, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/dotnet-maui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
runs-on: macos-13
steps:
- uses: actions/checkout@v1
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.1'
- name: Build demo
run: |
cd dotnet-maui
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ on:

jobs:
build-custom-demo:
runs-on: macos-12
runs-on: macos-13
defaults:
run:
working-directory: ios/GSSDKCustomDemo
steps:
- uses: actions/checkout@v2
- run: pod install
- run: xcodebuild build -scheme GSSDKCustomDemo -workspace GSSDKCustomDemo.xcworkspace -configuration Debug -sdk iphoneos \
ONLY_ACTIVE_ARCH=YES \
CODE_SIGNING_ALLOWED="NO"
build-simple-demo:
runs-on: macos-12
runs-on: macos-13
defaults:
run:
working-directory: ios/GSSDKSimpleDemo
steps:
- uses: actions/checkout@v2
- run: pod install
- run: xcodebuild build -scheme GSSDKSimpleDemo -workspace GSSDKSimpleDemo.xcworkspace -configuration Debug -sdk iphoneos \
ONLY_ACTIVE_ARCH=YES \
CODE_SIGNING_ALLOWED="NO"
7 changes: 3 additions & 4 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fastlane/README.md

google-credentials.json

# Exclude model files as they are copied from root assets
gssdk-core/src/main/assets/*.png

# Exclude language files as they are copied from root assets
# Exclude these assets as they are copied from root assets
gssdk/src/main/assets/*.png
gssdk/src/main/res/raw/ocr_languages.csv
*.traineddata
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ buildscript {
}
}
maven {
url 'https://s3.amazonaws.com/tgl.maven'
url 'https://repo.gradle.org/gradle/libs-releases'
content {
includeModule('com.twilio', 'apkscale')
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
// Patch until apkscale is fixed: https://github.com/twilio/apkscale/issues/10
classpath "com.twilio:apkscale:0.0.101"
classpath "com.twilio:apkscale:0.1.6"
classpath "androidx.benchmark:benchmark-gradle-plugin:1.2.0"
classpath "firebase.test.lab:plugin:2.6.2"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21'
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.9.10'
}
}

Expand All @@ -47,7 +47,7 @@ allprojects {
}

ext {
ndkVersion = '25.1.8937393'
ndkVersion = '26.2.11394342'
compileSdkVersion = 34
targetSdkVersion = 34
minSdkVersion = 21
Expand Down
10 changes: 1 addition & 9 deletions android/demo-custom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,8 @@ android {
}

dependencies {
implementation 'com.geniusscansdk:gssdk-core:4.21.0'
implementation 'com.geniusscansdk:gssdk-ocr:4.21.0'
implementation 'com.geniusscansdk:gssdk:5.0.0-beta9'

implementation 'androidx.fragment:fragment:1.6.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
}

task copyLanguageFile(type: Copy) {
from "../../assets/eng.traineddata"
into "src/main/res/raw"
}

preBuild.dependsOn copyLanguageFile
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,21 @@
import android.content.Context;
import android.os.AsyncTask;

import com.geniusscansdk.pdf.DocumentGenerator;
import com.geniusscansdk.core.TextLayout;
import com.geniusscansdk.demo.R;
import com.geniusscansdk.demo.model.Page;
import com.geniusscansdk.ocr.OCREngineProgressListener;
import com.geniusscansdk.ocr.OcrConfiguration;
import com.geniusscansdk.ocr.OcrProcessor;
import com.geniusscansdk.ocr.OcrResult;
import com.geniusscansdk.pdf.DocumentGenerator;
import com.geniusscansdk.pdf.PDFDocument;
import com.geniusscansdk.pdf.PDFImageProcessor;
import com.geniusscansdk.pdf.PDFPage;
import com.geniusscansdk.pdf.PDFSize;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
* Created by guillaume on 25/10/16.
*/

public class PdfGenerationTask extends AsyncTask<Void, Integer, Exception> {

public interface OnPdfGeneratedListener {
Expand Down Expand Up @@ -75,17 +63,9 @@ protected Exception doInBackground(Void... params) {
OcrProcessor ocrProcessor = null;

if (isOCREnabled) {
try {
copyTessdataFiles();
} catch (IOException e) {
return new IOException("Cannot copy tessdata", e);
}
OcrConfiguration ocrConfiguration = new OcrConfiguration(Arrays.asList("eng"), getTessdataDirectory());
ocrProcessor = new OcrProcessor(context, ocrConfiguration, new OCREngineProgressListener() {
@Override
public void updateProgress(int progress) {
publishProgress(pageProgress + progress / pages.size());
}
OcrConfiguration ocrConfiguration = new OcrConfiguration(Arrays.asList("en-US"));
ocrProcessor = new OcrProcessor(context, ocrConfiguration, progress -> {
publishProgress(pageProgress + progress / pages.size());
});
}

Expand All @@ -106,12 +86,12 @@ public void updateProgress(int progress) {
}

// Export all pages in A4
pdfPages.add(new PDFPage(image.getAbsolutePath(), A4_SIZE, textLayout));
pdfPages.add(new PDFPage(image, A4_SIZE, textLayout));
pageIndex++;
}

// Here we don't protect the PDF document with a password
PDFDocument pdfDocument = new PDFDocument("test", null, null, new Date(), new Date(), pdfPages);
PDFDocument pdfDocument = new PDFDocument(pdfPages, /* title = */ "test");
try {
DocumentGenerator.Configuration configuration = new DocumentGenerator.Configuration(outputFile);
new DocumentGenerator(context).generatePDFDocument(pdfDocument, configuration);
Expand All @@ -136,36 +116,4 @@ protected void onProgressUpdate(Integer... values) {
progressDialog.setProgress(values[0]);
}
}

private void copyTessdataFiles() throws IOException {
File tessdataDir = getTessdataDirectory();

if (tessdataDir.exists()) {
return;
}

tessdataDir.mkdir();

InputStream in = context.getResources().openRawResource(R.raw.eng);
File engFile = new File(tessdataDir, "eng.traineddata");
OutputStream out = new FileOutputStream(engFile);

byte[] buffer = new byte[1024];
int len = in.read(buffer);
while (len != -1) {
out.write(buffer, 0, len);
len = in.read(buffer);
}
}

private File getTessdataDirectory() {
return new File(context.getExternalFilesDir(null), "tessdata");
}

private class PDFNoopImageProcessor extends PDFImageProcessor {
@Override
public String process(String inputFilePath) {
return inputFilePath;
}
}
}
Binary file removed android/demo-custom/src/main/res/raw/eng.traineddata
Binary file not shown.
11 changes: 1 addition & 10 deletions android/demo-simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ android {
}

dependencies {
implementation 'com.geniusscansdk:gssdk-core:4.21.0'
implementation 'com.geniusscansdk:gssdk-ocr:4.21.0'
implementation 'com.geniusscansdk:gssdk-scanflow:4.21.0'
implementation 'com.geniusscansdk:gssdk:5.0.0-beta9'

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
}

task copyLanguageFile(type: Copy) {
from "../../assets/eng.traineddata"
into "src/main/res/raw"
}

preBuild.dependsOn copyLanguageFile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
import android.util.Log;
import android.widget.TextView;

import com.geniusscansdk.core.GeniusScanSDK;
import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

import com.geniusscansdk.core.LicenseException;
import com.geniusscansdk.scanflow.ScanConfiguration;
import com.geniusscansdk.scanflow.ScanFlow;
Expand All @@ -21,13 +27,6 @@
import java.io.InputStream;
import java.util.Arrays;

import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();
Expand Down Expand Up @@ -68,11 +67,9 @@ private ScanConfiguration createBaseConfiguration() {
scanConfiguration.highlightColor = ContextCompat.getColor(this, R.color.colorAccent);

ScanConfiguration.OcrConfiguration ocrConfiguration = new ScanConfiguration.OcrConfiguration();
ocrConfiguration.languages = Arrays.asList("eng");
ocrConfiguration.languagesDirectory = getTessdataDirectory();
ocrConfiguration.languages = Arrays.asList("en-US");

scanConfiguration.ocrConfiguration = ocrConfiguration;
copyFileFromResource(R.raw.eng, new File(getTessdataDirectory(), "eng.traineddata"));

return scanConfiguration;
}
Expand Down Expand Up @@ -121,12 +118,6 @@ private void copyFileFromResource(@RawRes int fileResId, File destinationFile) {
}
}

private File getTessdataDirectory() {
File directory = new File(getExternalFilesDir(null), "tessdata");
directory.mkdirs();
return directory;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == ScanFlow.SCAN_REQUEST && resultCode == Activity.RESULT_OK && data != null) {
Expand All @@ -146,12 +137,14 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
// The license key is invalid or expired, either ask the user to update the app or provide a fallback
new AlertDialog.Builder(this)
.setMessage("Please update to the latest version.")
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {})
.show();
}
} catch (Exception e) {
Log.e(TAG, "Error during scan flow", e);
new AlertDialog.Builder(this)
.setMessage("An error occurred: " + e.getMessage())
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {})
.show();
}
} else {
Expand Down
Binary file removed android/demo-simple/src/main/res/raw/eng.traineddata
Binary file not shown.
2 changes: 1 addition & 1 deletion cordova-plugin-genius-scan-demo/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<engine name="android" spec="~12.0.0" />
<plugin name="cordova-plugin-file" spec="^6.0.1" />
<plugin name="cordova-plugin-preview-any-file" spec="^0.2.9" />
<plugin name="@thegrizzlylabs/cordova-plugin-genius-scan" spec="@thegrizzlylabs/cordova-plugin-genius-scan@4.21.0">
<plugin name="@thegrizzlylabs/cordova-plugin-genius-scan" spec="@thegrizzlylabs/cordova-plugin-genius-scan@5.0.0-beta9">
<variable name="CAMERA_USAGE_DESCRIPTION" value="Access camera for demo" />
</plugin>
</widget>
Binary file removed cordova-plugin-genius-scan-demo/www/eng.traineddata
Binary file not shown.
36 changes: 7 additions & 29 deletions cordova-plugin-genius-scan-demo/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@ function onError(error) {
alert("Error: " + JSON.stringify(error));
}

function copy(filepath, toDirectory, filename, callback) {
window.resolveLocalFileSystemURL(filepath, function(fileEntry) {
window.resolveLocalFileSystemURL(toDirectory, function(dirEntry) {
dirEntry.getFile(filename, { create: true, exclusive: false }, function(targetFileEntry) {
fileEntry.file(function(file) {
targetFileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function() {
callback();
};
fileWriter.write(file);
});
});
}, onError);
}, onError);
}, onError);
}

var app = {
initialize: function() {
document.addEventListener("deviceready", this.onDeviceReady.bind(this), false);
Expand Down Expand Up @@ -55,18 +38,13 @@ var app = {
};

function startScanFlow() {
var assetLanguageUri = `${cordova.file.applicationDirectory}www/eng.traineddata`
var appFolder = window.cordova.platformId == 'android' ? cordova.file.externalDataDirectory : cordova.file.dataDirectory;
copy(assetLanguageUri, appFolder, 'eng.traineddata', function() {
var configuration = {
source: 'camera',
ocrConfiguration: {
languages: ['eng'],
languagesDirectoryUrl: appFolder
}
};
cordova.plugins.GeniusScan.scanWithConfiguration(configuration, onScanFlowResult, onError);
});
var configuration = {
source: 'camera',
ocrConfiguration: {
languages: ['en-US']
}
};
cordova.plugins.GeniusScan.scanWithConfiguration(configuration, onScanFlowResult, onError);
}

function onScanFlowResult(result) {
Expand Down
23 changes: 1 addition & 22 deletions dotnet-maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ async void StartScanning(object sender, EventArgs args)
{
try
{
var appFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var languageFilePath = Path.Combine(appFolder, "eng.traineddata");
Console.WriteLine(languageFilePath);
if (!File.Exists(languageFilePath))
{
await DownloadFileAsync("https://github.com/tesseract-ocr/tessdata_fast/raw/main/eng.traineddata", languageFilePath);
}

var documentUrl = await scanFlowService.StartScanning("file://" + appFolder);
var documentUrl = await scanFlowService.StartScanning();

await Launcher.OpenAsync(new OpenFileRequest
{
Expand All @@ -40,17 +32,4 @@ await Launcher.OpenAsync(new OpenFileRequest
await DisplayAlert("Alert", "Error: " + e.Message, "OK");
}
}

private async Task DownloadFileAsync(string fileUrl, string downloadedFilePath)
{
var client = new HttpClient();

var downloadStream = await client.GetStreamAsync(fileUrl);

var fileStream = File.Create(downloadedFilePath);

await downloadStream.CopyToAsync(fileStream);
}
}


Loading
Loading