Эх сурвалжийг харах

1. 处理文字识别结果并输入到算法中。
2. 修改筛选文字识别结果的方法。

Ulric 2 сар өмнө
parent
commit
460ccb63bb

+ 3 - 2
app/src/main/java/com/ys/imageProcess/cv/Process.java

@@ -22,10 +22,11 @@ public class Process {
     /**
      * @param bitmap 图像
      * @param um 比例尺长度 (um)
-     * @param pos 文字左上角坐标
+     * @param posX 文字左上角 x 坐标
+     * @param posY 文字左上角 y 坐标
      * @return 识别结果
      */
-    public native DetectResult Detect(Bitmap bitmap, int um, int[] pos);
+    public native DetectResult Detect(Bitmap bitmap, int um, int posX, int posY);
 
     static {
         System.loadLibrary("ImageProcJni");

+ 5 - 2
app/src/main/java/com/ys/imageProcess/utils/StringTools.kt

@@ -1,5 +1,7 @@
 package com.ys.imageProcess.utils
 
+import android.content.ContentValues.TAG
+import android.util.Log
 import java.text.SimpleDateFormat
 import java.util.Date
 import java.util.Locale
@@ -39,9 +41,10 @@ fun scaleLength(label: String): Int {
                 str += it
             }
         }
-        len = str.toInt()
+        if (str.isNotEmpty()) {
+            len = str.toInt()
+        }
     }
-
     return len
 }
 

+ 18 - 11
app/src/main/java/com/ys/imageProcess/viewModel/WorkViewModel.kt

@@ -3,6 +3,7 @@ package com.ys.imageProcess.viewModel
 import android.content.ContentValues.TAG
 import android.content.Context
 import android.graphics.Bitmap
+import android.graphics.Point
 import android.graphics.PointF
 import android.net.Uri
 import android.util.Log
@@ -119,11 +120,18 @@ class WorkViewModel : ViewModel() {
                 val bitmap = ProcessDataStore.getProcessedImage(name)
 
                 val ocrRes = OCRModelLoader.runModel(bitmap!!)
+                var scale = 100
+                var topLeft = Point()
+
                 for (model in ocrRes) {
-                    val scale = scaleLength(model.label)
-                    Log.i(TAG, "OCR result: ${model.label}, $scale, ${model.points}")
+                    if (model.label.contains("0") && model.label.contains("m")) {
+                        scale = scaleLength(model.label)
+                        topLeft = model.points.first()
+                    }
                 }
 
+                Log.i(TAG, "--- $scale, $topLeft")
+
                 val store = ProcessedData(bitmap)
                 store.setMap(storedMap)
                 final = store
@@ -135,19 +143,18 @@ class WorkViewModel : ViewModel() {
                     updateInfoMap()
                     val ocrRes = OCRModelLoader.runModel(it)
                     var scale = 100
-                    val ocrPos = mutableListOf<Int>()
-                    if (ocrRes.isNotEmpty()) {
-                        scale = scaleLength(ocrRes.first().label)
-                        for (point in ocrRes.first().points) {
-                            ocrPos.add(point.x)
-                            ocrPos.add(point.y)
-                            break
+                    var topLeft = Point()
+
+                    for (model in ocrRes) {
+                        if (model.label.contains("0") && model.label.contains("m")) {
+                            scale = scaleLength(model.label)
+                            topLeft = model.points.first()
                         }
                     }
 
                     val result =
-                        Process().Detect(it, scale, ocrPos.toIntArray())
-                    Log.i(TAG, "--- $scale, $ocrPos")
+                        Process().Detect(it, scale, topLeft.x, topLeft.y)
+                    Log.i(TAG, "--- $scale, $topLeft")
                     val processed = ProcessedData(result.processedImage, result)
                     ProcessDataStore.saveResult(processed.map(), name)
                     ProcessDataStore.saveProcessedImage(

+ 1 - 1
app/src/main/jni/src/process.cpp

@@ -120,7 +120,7 @@ jobject GenerateBitmap(JNIEnv *env, int32_t width, int32_t height) {
 extern "C" {
 
 JNIEXPORT jobject JNICALL
-Java_com_ys_imageProcess_cv_Process_Detect(JNIEnv *env, jobject thiz, jobject bitmap, jint um, jintArray pos) {
+Java_com_ys_imageProcess_cv_Process_Detect(JNIEnv *env, jobject thiz, jobject bitmap, jint um, jint posX, jint posY) {
     cv::Mat in_mat;
 
     ARGB888Bitmap2BGR(env, bitmap, in_mat);