替换模型

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