Browse Source

比例尺长度识别

Ulric 2 tháng trước cách đây
mục cha
commit
fe15bcad79

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

@@ -19,7 +19,7 @@ public class Process {
         public double[] widthContour;
     }
 
-    public native DetectResult Detect(Bitmap bitmap, String um, int[] pos);
+    public native DetectResult Detect(Bitmap bitmap, int um, int[] pos);
 
     static {
         System.loadLibrary("ImageProcJni");

+ 10 - 1
app/src/main/java/com/ys/imageProcess/utils/StringTools.kt

@@ -21,7 +21,6 @@ fun fileSizeString(bytes: Long?): String {
     }
 
     return string
-
 }
 
 fun formatDate(date: Date, pattern: String, locale: Locale): String =
@@ -31,3 +30,13 @@ fun formatDate(timestamp: Long, pattern: String, locale: Locale): String {
     val date = Date(timestamp)
     return SimpleDateFormat(pattern, locale).format(date)
 }
+
+fun scaleLength(label: String): Int {
+    var len = 100
+    if (label.contains("um")) {
+        len = label.toInt()
+    }
+
+    return len
+}
+

+ 3 - 2
app/src/main/java/com/ys/imageProcess/viewModel/WorkViewModel.kt

@@ -26,6 +26,7 @@ import com.ys.imageProcess.ui.work.minZoom
 import com.ys.imageProcess.ui.work.zoomStep
 import com.ys.imageProcess.utils.fileSizeString
 import com.ys.imageProcess.utils.formatDate
+import com.ys.imageProcess.utils.scaleLength
 import com.ys.imageProcess.utils.uriToBitmap
 import com.ys.imageProcess.utils.zoomToFit
 import kotlinx.coroutines.CoroutineScope
@@ -134,10 +135,10 @@ class WorkViewModel : ViewModel() {
                     isAlgRunning = true
                     updateInfoMap()
                     val ocrRes = OCRModelLoader.runModel(it)
-                    var ocrStr = ""
+                    var ocrStr = 100
                     val ocrPos = mutableListOf<Int>()
                     if (ocrRes.isNotEmpty()) {
-                        ocrStr = ocrRes.first().label
+                        ocrStr = scaleLength(ocrRes.first().label)
                         for (point in ocrRes.first().points) {
                             ocrPos.add(point.x)
                             ocrPos.add(point.y)

+ 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, jstring um, jintArray pos) {
+Java_com_ys_imageProcess_cv_Process_Detect(JNIEnv *env, jobject thiz, jobject bitmap, jint um, jintArray pos) {
     cv::Mat in_mat;
 
     ARGB888Bitmap2BGR(env, bitmap, in_mat);