替换模型

This commit is contained in:
mazengfei
2026-03-03 17:47:17 +08:00
parent 9a5258ad34
commit 9a7939d2ac
6 changed files with 426 additions and 387 deletions
Binary file not shown.
+139 -124
View File
@@ -14,19 +14,23 @@
"大葱WP2026013000025", "大葱WP2026013000025",
"姜[黄姜]WP2025112000071", "姜[黄姜]WP2025112000071",
"娃娃菜WP2026020200005", "娃娃菜WP2026020200005",
"小白菜WP2026022800031",
"小米辣椒WP2026013000027", "小米辣椒WP2026013000027",
"小葱WP2026013000029", "小葱WP2026013000029",
"山药(带皮)WP2026020200008", "山药(带皮)WP2026020200008",
"巨人笋", "巨人笋",
"广东菜心WP2025120100014", "广东菜心WP2025120100014",
"杏鲍菇WP2026022700030",
"松花蛋", "松花蛋",
"松茸菌WP2025120100016", "松茸菌WP2025120100016",
"沙葱", "沙葱",
"洋葱(鲜)[葱头]WP2025111000061", "洋葱(鲜)[葱头]WP2025111000061",
"海带(浸)[江白菜,昆布]WP2026022800035",
"牛腩WP2025110700043", "牛腩WP2025110700043",
"猪五花肉WP2026020300048", "猪五花肉WP2026020300048",
"猪腿肉WP2025110700040", "猪腿肉WP2025110700040",
"玉米WP2025120100017", "玉米WP2025120100017",
"玉米糁(黄)WP2026022800038",
"番茄WP2025110700016", "番茄WP2025110700016",
"白吉饼WP2026013000024", "白吉饼WP2026013000024",
"笋", "笋",
@@ -52,6 +56,7 @@
"蒜WP2025111400003", "蒜WP2025111400003",
"蒜苗WP2026013000028", "蒜苗WP2026013000028",
"蒸鱼豉油WP2026013000032", "蒸鱼豉油WP2026013000032",
"薏米[薏仁米,苡米]WP2026022800037",
"西兰花[绿菜花]WP2025110700029", "西兰花[绿菜花]WP2025110700029",
"西葫芦", "西葫芦",
"豆腐皮WP2025111000059", "豆腐皮WP2025111000059",
@@ -91,67 +96,72 @@
"大葱WP2026013000025": 11, "大葱WP2026013000025": 11,
"姜[黄姜]WP2025112000071": 12, "姜[黄姜]WP2025112000071": 12,
"娃娃菜WP2026020200005": 13, "娃娃菜WP2026020200005": 13,
"小米辣椒WP2026013000027": 14, "小白菜WP2026022800031": 14,
"小WP2026013000029": 15, "小米辣椒WP2026013000027": 15,
"山药(带皮)WP2026020200008": 16, "小葱WP2026013000029": 16,
"巨人笋": 17, "山药(带皮)WP2026020200008": 17,
"广东菜心WP2025120100014": 18, "巨人笋": 18,
"松花蛋": 19, "广东菜心WP2025120100014": 19,
"松茸菌WP2025120100016": 20, "杏鲍菇WP2026022700030": 20,
"沙葱": 21, "松花蛋": 21,
"洋葱(鲜)[葱头]WP2025111000061": 22, "松茸菌WP2025120100016": 22,
"牛腩WP2025110700043": 23, "沙葱": 23,
"猪五花肉WP2026020300048": 24, "洋葱(鲜)[葱头]WP2025111000061": 24,
"猪腿肉WP2025110700040": 25, "海带(浸)[江白菜,昆布]WP2026022800035": 25,
"玉米WP2025120100017": 26, "牛腩WP2025110700043": 26,
"番茄WP2025110700016": 27, "猪五花肉WP2026020300048": 27,
"白吉饼WP2026013000024": 28, "猪腿肉WP2025110700040": 28,
"": 29, "玉米WP2025120100017": 29,
"粉丝": 30, "玉米糁(黄)WP2026022800038": 30,
"紫甘蓝": 31, "番茄WP2025110700016": 31,
"红提子WP2025111900006": 32, "白吉饼WP2026013000024": 32,
"红椒": 33, "": 33,
"红美人椒WP2026020300049": 34, "粉丝": 34,
"红薯": 35, "紫甘蓝": 35,
"红薯粉条(袋)": 36, "红提子WP2025111900006": 36,
"羊排WP2025120300021": 37, "红椒": 37,
"羊血WP2026013000038": 38, "红美人椒WP2026020300049": 38,
"胡萝卜WP2025110600008": 39, "红薯": 39,
"芋头": 40, "红薯粉条(袋)": 40,
"花卷": 41, "羊排WP2025120300021": 41,
"芹菜WP2025111000065": 42, "羊血WP2026013000038": 42,
"苦菊": 43, "胡萝卜WP2025110600008": 43,
"茄子(紫皮,长)WP2025110700024": 44, "芋头": 44,
"茼蒿WP2026020200045": 45, "花卷": 45,
"莲藕(带皮)": 46, "芹菜WP2025111000065": 46,
"莴笋(鲜)[莴苣]WP2026020200009": 47, "苦菊": 47,
"菜花(白色)[花椰菜]": 48, "茄子(紫皮,长)WP2025110700024": 48,
"WP2025111400003": 49, "茼蒿WP2026020200045": 49,
"蒜苗WP2026013000028": 50, "莲藕(带皮)": 50,
"蒸鱼豉油WP2026013000032": 51, "莴笋(鲜)[莴苣]WP2026020200009": 51,
"西兰花[绿菜花]WP2025110700029": 52, "菜花(白色)[花椰菜]": 52,
"西葫芦": 53, "蒜WP2025111400003": 53,
"豆腐皮WP2025111000059": 54, "蒜苗WP2026013000028": 54,
"豆角": 55, "蒸鱼豉油WP2026013000032": 55,
"辣椒(红,小)WP2025111000066": 56, "薏米[薏仁米,苡米]WP2026022800037": 56,
"辣椒(青辣椒,螺丝椒)WP2025110700017": 57, "西兰花[绿菜花]WP2025110700029": 57,
"醪糟": 58, "西葫芦": 58,
"金针菇WP2025111900010": 59, "豆腐皮WP2025111000059": 59,
"青线椒WP2026013000031": 60, "豆角": 60,
"韭黄": 61, "辣椒(红,小)WP2025111000066": 61,
"香菇": 62, "辣椒(青辣椒,螺丝椒)WP2025110700017": 62,
"香菜WP2026013000030": 63, "醪糟": 63,
"马铃薯[土豆、洋芋]WP2026012900001": 64, "金针菇WP2025111900010": 64,
"鸡全腿(带骨)": 65, "青线椒WP2026013000031": 65,
"鸡翅(带骨)": 66, "韭黄": 66,
"鸡腿肉WP2025110700048": 67, "香菇": 67,
"鸡腿(带骨)": 68, "香菜WP2026013000030": 68,
"鸡蛋(代表值)WP2026013000039": 69, "马铃薯[土豆、洋芋]WP2026012900001": 69,
"麦芹": 70, "鸡全腿(带骨)": 70,
"黄瓜(鲜)[胡瓜]WP2025110700031": 71, "鸡翅(带骨)": 71,
"黄豆芽WP2026020200042": 72, "鸡腿肉WP2025110700048": 72,
"黑袋子": 73, "鸡腿(带骨)": 73,
"黑鱼(整条鱼)WP2025110600012": 74 "鸡蛋(代表值)WP2026013000039": 74,
"麦芹": 75,
"黄瓜(鲜)[胡瓜]WP2025110700031": 76,
"黄豆芽WP2026020200042": 77,
"黑袋子": 78,
"黑鱼(整条鱼)WP2025110600012": 79
}, },
"idx_to_class": { "idx_to_class": {
"0": "三黄鸡", "0": "三黄鸡",
@@ -168,69 +178,74 @@
"11": "大葱WP2026013000025", "11": "大葱WP2026013000025",
"12": "姜[黄姜]WP2025112000071", "12": "姜[黄姜]WP2025112000071",
"13": "娃娃菜WP2026020200005", "13": "娃娃菜WP2026020200005",
"14": "小米辣椒WP2026013000027", "14": "小白菜WP2026022800031",
"15": "小WP2026013000029", "15": "小米辣椒WP2026013000027",
"16": "山药(带皮)WP2026020200008", "16": "小葱WP2026013000029",
"17": "巨人笋", "17": "山药(带皮)WP2026020200008",
"18": "广东菜心WP2025120100014", "18": "巨人笋",
"19": "松花蛋", "19": "广东菜心WP2025120100014",
"20": "松茸菌WP2025120100016", "20": "杏鲍菇WP2026022700030",
"21": "沙葱", "21": "松花蛋",
"22": "洋葱(鲜)[葱头]WP2025111000061", "22": "松茸菌WP2025120100016",
"23": "牛腩WP2025110700043", "23": "沙葱",
"24": "猪五花肉WP2026020300048", "24": "洋葱(鲜)[葱头]WP2025111000061",
"25": "猪腿肉WP2025110700040", "25": "海带(浸)[江白菜,昆布]WP2026022800035",
"26": "玉米WP2025120100017", "26": "牛腩WP2025110700043",
"27": "番茄WP2025110700016", "27": "猪五花肉WP2026020300048",
"28": "白吉饼WP2026013000024", "28": "猪腿肉WP2025110700040",
"29": "", "29": "玉米WP2025120100017",
"30": "粉丝", "30": "玉米糁(黄)WP2026022800038",
"31": "紫甘蓝", "31": "番茄WP2025110700016",
"32": "红提子WP2025111900006", "32": "白吉饼WP2026013000024",
"33": "红椒", "33": "",
"34": "红美人椒WP2026020300049", "34": "粉丝",
"35": "红薯", "35": "紫甘蓝",
"36": "红薯粉条(袋)", "36": "红提子WP2025111900006",
"37": "羊排WP2025120300021", "37": "红椒",
"38": "羊血WP2026013000038", "38": "红美人椒WP2026020300049",
"39": "胡萝卜WP2025110600008", "39": "红薯",
"40": "芋头", "40": "红薯粉条(袋)",
"41": "花卷", "41": "羊排WP2025120300021",
"42": "芹菜WP2025111000065", "42": "羊血WP2026013000038",
"43": "苦菊", "43": "胡萝卜WP2025110600008",
"44": "茄子(紫皮,长)WP2025110700024", "44": "芋头",
"45": "茼蒿WP2026020200045", "45": "花卷",
"46": "莲藕(带皮)", "46": "芹菜WP2025111000065",
"47": "莴笋(鲜)[莴苣]WP2026020200009", "47": "苦菊",
"48": "菜花(白色)[花椰菜]", "48": "茄子(紫皮,长)WP2025110700024",
"49": "WP2025111400003", "49": "茼蒿WP2026020200045",
"50": "蒜苗WP2026013000028", "50": "莲藕(带皮)",
"51": "蒸鱼豉油WP2026013000032", "51": "莴笋(鲜)[莴苣]WP2026020200009",
"52": "西兰花[绿菜花]WP2025110700029", "52": "菜花(白色)[花椰菜]",
"53": "西葫芦", "53": "蒜WP2025111400003",
"54": "豆腐皮WP2025111000059", "54": "蒜苗WP2026013000028",
"55": "豆角", "55": "蒸鱼豉油WP2026013000032",
"56": "辣椒(红,小)WP2025111000066", "56": "薏米[薏仁米,苡米]WP2026022800037",
"57": "辣椒(青辣椒,螺丝椒)WP2025110700017", "57": "西兰花[绿菜花]WP2025110700029",
"58": "醪糟", "58": "西葫芦",
"59": "金针菇WP2025111900010", "59": "豆腐皮WP2025111000059",
"60": "青线椒WP2026013000031", "60": "豆角",
"61": "韭黄", "61": "辣椒(红,小)WP2025111000066",
"62": "香菇", "62": "辣椒(青辣椒,螺丝椒)WP2025110700017",
"63": "香菜WP2026013000030", "63": "醪糟",
"64": "马铃薯[土豆、洋芋]WP2026012900001", "64": "金针菇WP2025111900010",
"65": "鸡全腿(带骨)", "65": "青线椒WP2026013000031",
"66": "鸡翅(带骨)", "66": "韭黄",
"67": "鸡腿肉WP2025110700048", "67": "香菇",
"68": "鸡腿(带骨)", "68": "香菜WP2026013000030",
"69": "鸡蛋(代表值)WP2026013000039", "69": "马铃薯[土豆、洋芋]WP2026012900001",
"70": "麦芹", "70": "鸡全腿(带骨)",
"71": "黄瓜(鲜)[胡瓜]WP2025110700031", "71": "鸡翅(带骨)",
"72": "黄豆芽WP2026020200042", "72": "鸡腿肉WP2025110700048",
"73": "黑袋子", "73": "鸡腿(带骨)",
"74": "黑鱼(整条鱼)WP2025110600012" "74": "鸡蛋(代表值)WP2026013000039",
"75": "麦芹",
"76": "黄瓜(鲜)[胡瓜]WP2025110700031",
"77": "黄豆芽WP2026020200042",
"78": "黑袋子",
"79": "黑鱼(整条鱼)WP2025110600012"
}, },
"embedding_dim": 512, "embedding_dim": 512,
"total_images": 4254, "total_images": 1950,
"build_time": "2026-02-10T08:08:53.308245" "build_time": "2026-03-03T15:31:53.107596"
} }
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
package com.sw.inbound.activity package com.sw.inbound.activity
import android.graphics.Bitmap
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
@@ -43,7 +44,9 @@ import com.sw.inbound.objbox.FoodModule.IdNameScore
import com.sw.inbound.objbox.Food_ import com.sw.inbound.objbox.Food_
import com.sw.inbound.objbox.ObjectBox import com.sw.inbound.objbox.ObjectBox
import com.sw.inbound.sdk.SensorScaleUtils import com.sw.inbound.sdk.SensorScaleUtils
import com.sw.inbound.utils.AssetsTool
import com.sw.inbound.utils.BitmapCropper import com.sw.inbound.utils.BitmapCropper
import com.sw.inbound.utils.BitmapSaver
import com.sw.inbound.utils.CameraUtils import com.sw.inbound.utils.CameraUtils
import com.sw.inbound.utils.DateTimeUtils import com.sw.inbound.utils.DateTimeUtils
import com.sw.inbound.utils.ImageUtil import com.sw.inbound.utils.ImageUtil
@@ -351,32 +354,28 @@ abstract class GoodsListActivity : ComponentActivity() {
} }
var isShowRecognizeDialog = true var isShowRecognizeDialog = true
private suspend fun searchFood(uri: Uri) {
ImageUtil.uriToBitmap(this, uri)?.let { bitmap -> private suspend fun readBitmap(bitmap: Bitmap) {
val newBmp = BitmapCropper.cropCenter( // binding.imageView.setImageBitmap(bitmap)
original = bitmap, val file = BitmapSaver.saveToAppFilesDir(
targetWidth = 1000, targetHeight = 1300, bitmap,
offsetX = 30, offsetY = 100 this,
"IMG_CROP_${System.currentTimeMillis()}.jpg"
) )
// val file = BitmapSaver.saveToAppFilesDir( Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}")
// newBmp,
// this,
// "IMG_CROP_${System.currentTimeMillis()}.jpg"
// )
// Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}")
//var foodList = FoodModule.queryFood(newBmp) //var foodList = FoodModule.queryFood(newBmp)
//物品编号 //物品编号
//foodList = foodList.map { "WP"+it.split("WP")[1] } //foodList = foodList.map { "WP"+it.split("WP")[1] }
//物品名称 //物品名称
//foodList = foodList.map { it.split("WP")[0] } //foodList = foodList.map { it.split("WP")[0] }
val foodList = FoodModule.getFoodScoreList(newBmp) val foodList = FoodModule.getFoodScoreList(bitmap)
if (bitmap.isRecycled.not()) { if (bitmap.isRecycled.not()) {
bitmap.recycle() bitmap.recycle()
} }
if (newBmp.isRecycled.not()) { // if (newBmp.isRecycled.not()) {
newBmp.recycle() // newBmp.recycle()
} // }
// val count = foodList.count { it.score < 0.15 } // val count = foodList.count { it.score < 0.15 }
val count = foodList.size val count = foodList.size
if (count == 0) { if (count == 0) {
@@ -384,12 +383,12 @@ abstract class GoodsListActivity : ComponentActivity() {
var tempList = foodList.filter { it.name.contains("黑袋子").not() } var tempList = foodList.filter { it.name.contains("黑袋子").not() }
if (tempList.isEmpty()) { if (tempList.isEmpty()) {
recognizeFoodError() recognizeFoodError()
return@let return
} }
tempList = tempList.subList(0, 1) tempList = tempList.subList(0, 1)
tempList.forEach { it.name = it.name.split("WP")[0] } tempList.forEach { it.name = it.name.split("WP")[0] }
recognizeGoodsList(tempList) recognizeGoodsList(tempList)
return@let return
} }
//if (foodList.isEmpty()) { //if (foodList.isEmpty()) {
// recognizeFoodError() // recognizeFoodError()
@@ -411,10 +410,25 @@ abstract class GoodsListActivity : ComponentActivity() {
} }
handleGoodsResult(mutableListOf()) handleGoodsResult(mutableListOf())
} }
return@let return
} }
recognizeGoodsList(foodList) recognizeGoodsList(foodList)
} }
private suspend fun searchFood(uri: Uri) {
// AssetsTool.loadImageBitmapFromAssets(this, "img_2028763001103859714.jpg") {
// lifecycleScope.launch {
// readBitmap(it)
// }
// }
ImageUtil.uriToBitmap(this, uri)?.let { bitmap ->
val newBmp = BitmapCropper.cropCenter(
original = bitmap,
targetWidth = 1000, targetHeight = 1300,
offsetX = 30, offsetY = 100
)
readBitmap(newBmp)
}
} }
private fun recognizeGoodsList(foodList: List<IdNameScore>) { private fun recognizeGoodsList(foodList: List<IdNameScore>) {
@@ -795,7 +809,7 @@ abstract class GoodsListActivity : ComponentActivity() {
} }
} }
private fun logInfo(msg:String) { private fun logInfo(msg: String) {
Timber.tag(TAG).d(msg) Timber.tag(TAG).d(msg)
LogSaveUtil.saveLogFile(msg) LogSaveUtil.saveLogFile(msg)
} }
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@mipmap/bg" android:background="@mipmap/bg"
@@ -240,4 +244,10 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<!-- <ImageView-->
<!-- android:id="@+id/imageView"-->
<!-- android:layout_width="500dp"-->
<!-- android:layout_height="500dp"/>-->
</FrameLayout>