Skip to content

Commit d1b2d07

Browse files
author
Persie
committed
removed tessearct, upgraded dependencies
1 parent 109aa9f commit d1b2d07

File tree

4 files changed

+11
-230
lines changed

4 files changed

+11
-230
lines changed

android/build.gradle

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:7.1.2'
11+
classpath 'com.android.tools.build:gradle:8.4.2'
1212
}
1313
}
1414

1515
rootProject.allprojects {
1616
repositories {
1717
google()
1818
mavenCentral()
19-
flatDir{
20-
dirs project(":flutter_vision").file("libs")
21-
}
2219
maven {
2320
url 'https://jitpack.io'
2421
}
@@ -53,15 +50,13 @@ android {
5350
}
5451
}
5552
dependencies{
56-
//implementation (files('libs/tesseract4android-release.aar'))
57-
api(name:"tesseract4android-release", ext: "aar")
5853
implementation 'com.github.vladiH:opencv-android:v1.0.0'
59-
implementation 'org.tensorflow:tensorflow-lite:2.10.0'
60-
implementation 'org.tensorflow:tensorflow-lite-api:2.10.0'
61-
implementation 'org.tensorflow:tensorflow-lite-gpu:2.10.0'
62-
implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.10.0'
63-
implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.3'
64-
implementation 'org.tensorflow:tensorflow-lite-support:0.4.3'
65-
implementation 'org.tensorflow:tensorflow-lite-metadata:0.4.3'
66-
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.11.0'
54+
implementation 'org.tensorflow:tensorflow-lite:2.17.0'
55+
implementation 'org.tensorflow:tensorflow-lite-api:2.17.0'
56+
implementation 'org.tensorflow:tensorflow-lite-gpu:2.17.0'
57+
implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.17.0'
58+
implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'
59+
implementation 'org.tensorflow:tensorflow-lite-support:0.5.0'
60+
implementation 'org.tensorflow:tensorflow-lite-metadata:0.5.0'
61+
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.16.1'
6762
}
-11.5 MB
Binary file not shown.

android/src/main/java/com/vladih/computer_vision/flutter_vision/FlutterVisionPlugin.java

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33
import android.content.Context;
44
import android.graphics.Bitmap;
55
import android.graphics.BitmapFactory;
6-
import android.graphics.Matrix;
76

87
import androidx.annotation.NonNull;
98

10-
import com.vladih.computer_vision.flutter_vision.models.Tesseract;
119
import com.vladih.computer_vision.flutter_vision.models.Yolo;
1210
import com.vladih.computer_vision.flutter_vision.models.Yolov8;
1311
import com.vladih.computer_vision.flutter_vision.models.Yolov5;
1412
import com.vladih.computer_vision.flutter_vision.models.Yolov8Seg;
1513
import com.vladih.computer_vision.flutter_vision.utils.utils;
1614

1715
import org.opencv.android.OpenCVLoader;
18-
import org.opencv.android.Utils;
19-
import org.opencv.core.Mat;
2016

2117
import java.nio.ByteBuffer;
2218
import java.util.ArrayList;
@@ -41,7 +37,6 @@ public class FlutterVisionPlugin implements FlutterPlugin, MethodCallHandler {
4137
private Context context;
4238
private FlutterAssets assets;
4339
private Yolo yolo_model;
44-
private Tesseract tesseract_model;
4540

4641
private ExecutorService executor;
4742

@@ -61,7 +56,6 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
6156
this.methodChannel.setMethodCallHandler(null);
6257
this.methodChannel = null;
6358
this.assets = null;
64-
close_tesseract();
6559
close_yolo();
6660
this.executor.shutdownNow();
6761
} catch (Exception e) {
@@ -84,17 +78,7 @@ private void setupChannel(Context context, FlutterAssets assets, BinaryMessenger
8478
@Override
8579
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
8680
// Handle method calls from Flutter
87-
if (call.method.equals("loadOcrModel")) {
88-
try {
89-
load_ocr_model((Map) call.arguments);
90-
} catch (Exception e) {
91-
result.error("100", "Error on load ocr components", e);
92-
}
93-
} else if (call.method.equals("ocrOnFrame")) {
94-
ocr_on_frame((Map) call.arguments, result);
95-
} else if (call.method.equals("closeOcrModel")) {
96-
close_ocr_model(result);
97-
} else if (call.method.equals("loadYoloModel")) {
81+
if (call.method.equals("loadYoloModel")) {
9882
try {
9983
load_yolo_model((Map) call.arguments);
10084
result.success("ok");
@@ -107,69 +91,11 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
10791
yolo_on_image((Map) call.arguments, result);
10892
} else if (call.method.equals("closeYoloModel")) {
10993
close_yolo_model(result);
110-
} else if (call.method.equals("loadTesseractModel")) {
111-
try {
112-
load_tesseract_model((Map) call.arguments);
113-
result.success("ok");
114-
} catch (Exception e) {
115-
result.error("100", "Error on load Tesseract model", e);
116-
}
117-
} else if (call.method.equals("tesseractOnImage")) {
118-
tesseract_on_image((Map) call.arguments, result);
119-
} else if (call.method.equals("closeTesseractModel")) {
120-
close_tesseract_model(result);
121-
} else {
94+
}else {
12295
result.notImplemented();
12396
}
12497
}
12598

126-
private void load_ocr_model(Map<String, Object> args) throws Exception {
127-
load_yolo_model(args);
128-
load_tesseract_model(args);
129-
}
130-
131-
private void ocr_on_frame(Map<String, Object> args, Result result) {
132-
try {
133-
List<byte[]> image = (ArrayList) args.get("bytesList");
134-
int image_height = (int) args.get("image_height");
135-
int image_width = (int) args.get("image_width");
136-
float iou_threshold = (float) (double) (args.get("iou_threshold"));
137-
float conf_threshold = (float) (double) (args.get("conf_threshold"));
138-
float class_threshold = (float) (double) (args.get("class_threshold"));
139-
List<Integer> class_is_text = (List<Integer>) args.get("class_is_text");
140-
Bitmap bitmap = utils.feedInputToBitmap(context.getApplicationContext(), image, image_height, image_width, 90);
141-
int[] shape = yolo_model.getInputTensor().shape();
142-
ByteBuffer byteBuffer = utils.feedInputTensor(bitmap, shape[1], shape[2], image_width, image_height, 0, 255);
143-
144-
List<Map<String, Object>> yolo_results = yolo_model.detect_task(byteBuffer, image_height, image_width, iou_threshold, conf_threshold, class_threshold);
145-
for (Map<String, Object> yolo_result : yolo_results) {
146-
float[] box = (float[]) yolo_result.get("box");
147-
if (class_is_text.contains((int) box[5])) {
148-
Bitmap crop = utils.crop_bitmap(bitmap,
149-
box[0], box[1], box[2], box[3]);
150-
//utils.getScreenshotBmp(crop, "crop");
151-
Bitmap tmp = crop.copy(crop.getConfig(), crop.isMutable());
152-
yolo_result.put("text", tesseract_model.predict_text(tmp));
153-
} else {
154-
yolo_result.put("text", "");
155-
}
156-
}
157-
result.success(yolo_results);
158-
} catch (Exception e) {
159-
result.error("100", "Ocr error", e);
160-
}
161-
}
162-
163-
private void close_ocr_model(Result result) {
164-
try {
165-
close_tesseract();
166-
close_yolo();
167-
result.success("OCR model closed succesfully");
168-
} catch (Exception e) {
169-
result.error("100", "Fail closed ocr model", e);
170-
}
171-
}
172-
17399
private void load_yolo_model(Map<String, Object> args) throws Exception {
174100
String model = "";
175101
final Object is_asset_obj = args.get("is_asset");
@@ -323,68 +249,6 @@ private void close_yolo_model(Result result) {
323249
}
324250
}
325251

326-
private void load_tesseract_model(Map<String, Object> args) throws Exception {
327-
final String tess_data = args.get("tess_data").toString();
328-
final Map<String, String> arg = (Map<String, String>) args.get("arg");
329-
final String language = args.get("language").toString();
330-
tesseract_model = new Tesseract(tess_data, arg, language);
331-
tesseract_model.initialize_model();
332-
}
333-
334-
class PredictionTask implements Runnable {
335-
private Tesseract tesseract;
336-
private Bitmap bitmap;
337-
private Result result;
338-
339-
public PredictionTask(Tesseract tesseract, Map<String, Object> args, Result result) {
340-
byte[] image = (byte[]) args.get("bytesList");
341-
this.tesseract = tesseract;
342-
this.bitmap = BitmapFactory.decodeByteArray(image, 0, image.length);
343-
this.result = result;
344-
}
345-
346-
@Override
347-
public void run() {
348-
try {
349-
Mat mat = utils.rgbBitmapToMatGray(bitmap);
350-
double angle = utils.computeSkewAngle(mat.clone());
351-
mat = utils.deskew(mat, angle);
352-
mat = utils.filterTextFromImage(mat);
353-
bitmap = Bitmap.createBitmap(mat.width(), mat.height(), Bitmap.Config.ARGB_8888);
354-
Utils.matToBitmap(mat, bitmap);
355-
// utils.getScreenshotBmp(bitmap,"TESSEREACT");
356-
result.success(tesseract.predict_text(bitmap));
357-
} catch (Exception e) {
358-
result.error("100", "Prediction text Error", e);
359-
}
360-
}
361-
}
362-
363-
private void tesseract_on_image(Map<String, Object> args, Result result) {
364-
try {
365-
PredictionTask predictionTask = new PredictionTask(tesseract_model, args, result);
366-
executor.submit(predictionTask);
367-
} catch (Exception e) {
368-
result.error("100", "Prediction Error", e);
369-
}
370-
}
371-
372-
private void close_tesseract_model(Result result) {
373-
try {
374-
close_tesseract();
375-
result.success("Tesseract model closed succesfully");
376-
} catch (Exception e) {
377-
result.error("100", "close_tesseract_model error", e);
378-
}
379-
}
380-
381-
private void close_tesseract(){
382-
if (tesseract_model != null) {
383-
tesseract_model.close();
384-
tesseract_model = null;
385-
}
386-
}
387-
388252
private void close_yolo(){
389253
if (yolo_model != null) {
390254
yolo_model.close();

android/src/main/java/com/vladih/computer_vision/flutter_vision/models/Tesseract.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)