替换模型,联调优化
This commit is contained in:
Binary file not shown.
@@ -3,42 +3,57 @@
|
||||
"圆白菜[卷心菜,包菜]WP2025111000063",
|
||||
"大白菜WP2025111000064",
|
||||
"大葱WP2025111000060",
|
||||
"姜[黄姜]WP2025112000071",
|
||||
"洋葱(鲜)[葱头]WP2025111000061",
|
||||
"番茄WP2025110700016",
|
||||
"红提子WP2025111900006",
|
||||
"胡萝卜WP2025110600008",
|
||||
"芹菜WP2025111000065",
|
||||
"茄子(紫皮,长)WP2025110700024",
|
||||
"莴笋(鲜)[莴苣]WP2025111000056",
|
||||
"西兰花[绿菜花]WP2025110700029",
|
||||
"辣椒(青辣椒,螺丝椒)WP2025110700017",
|
||||
"黄瓜(鲜)[胡瓜]WP2025110700031"
|
||||
"鸡蛋(代表值)WP2025112000070",
|
||||
"黄瓜(鲜)[胡瓜]WP2025110700031",
|
||||
"黑袋子"
|
||||
],
|
||||
"class_to_idx": {
|
||||
"圆白菜[卷心菜,包菜]WP2025111000063": 0,
|
||||
"大白菜WP2025111000064": 1,
|
||||
"大葱WP2025111000060": 2,
|
||||
"洋葱(鲜)[葱头]WP2025111000061": 3,
|
||||
"番茄WP2025110700016": 4,
|
||||
"胡萝卜WP2025110600008": 5,
|
||||
"芹菜WP2025111000065": 6,
|
||||
"茄子(紫皮,长)WP2025110700024": 7,
|
||||
"西兰花[绿菜花]WP2025110700029": 8,
|
||||
"辣椒(青辣椒,螺丝椒)WP2025110700017": 9,
|
||||
"黄瓜(鲜)[胡瓜]WP2025110700031": 10
|
||||
"姜[黄姜]WP2025112000071": 3,
|
||||
"洋葱(鲜)[葱头]WP2025111000061": 4,
|
||||
"番茄WP2025110700016": 5,
|
||||
"红提子WP2025111900006": 6,
|
||||
"胡萝卜WP2025110600008": 7,
|
||||
"芹菜WP2025111000065": 8,
|
||||
"茄子(紫皮,长)WP2025110700024": 9,
|
||||
"莴笋(鲜)[莴苣]WP2025111000056": 10,
|
||||
"西兰花[绿菜花]WP2025110700029": 11,
|
||||
"辣椒(青辣椒,螺丝椒)WP2025110700017": 12,
|
||||
"鸡蛋(代表值)WP2025112000070": 13,
|
||||
"黄瓜(鲜)[胡瓜]WP2025110700031": 14,
|
||||
"黑袋子": 15
|
||||
},
|
||||
"idx_to_class": {
|
||||
"0": "圆白菜[卷心菜,包菜]WP2025111000063",
|
||||
"1": "大白菜WP2025111000064",
|
||||
"2": "大葱WP2025111000060",
|
||||
"3": "洋葱(鲜)[葱头]WP2025111000061",
|
||||
"4": "番茄WP2025110700016",
|
||||
"5": "胡萝卜WP2025110600008",
|
||||
"6": "芹菜WP2025111000065",
|
||||
"7": "茄子(紫皮,长)WP2025110700024",
|
||||
"8": "西兰花[绿菜花]WP2025110700029",
|
||||
"9": "辣椒(青辣椒,螺丝椒)WP2025110700017",
|
||||
"10": "黄瓜(鲜)[胡瓜]WP2025110700031"
|
||||
"3": "姜[黄姜]WP2025112000071",
|
||||
"4": "洋葱(鲜)[葱头]WP2025111000061",
|
||||
"5": "番茄WP2025110700016",
|
||||
"6": "红提子WP2025111900006",
|
||||
"7": "胡萝卜WP2025110600008",
|
||||
"8": "芹菜WP2025111000065",
|
||||
"9": "茄子(紫皮,长)WP2025110700024",
|
||||
"10": "莴笋(鲜)[莴苣]WP2025111000056",
|
||||
"11": "西兰花[绿菜花]WP2025110700029",
|
||||
"12": "辣椒(青辣椒,螺丝椒)WP2025110700017",
|
||||
"13": "鸡蛋(代表值)WP2025112000070",
|
||||
"14": "黄瓜(鲜)[胡瓜]WP2025110700031",
|
||||
"15": "黑袋子"
|
||||
},
|
||||
"embedding_dim": 512,
|
||||
"total_images": 770,
|
||||
"build_time": "2025-11-13T16:28:46.501957"
|
||||
"total_images": 1120,
|
||||
"build_time": "2025-11-21T16:37:50.560656"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15]
|
||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.viewModels
|
||||
import androidx.camera.view.PreviewView
|
||||
@@ -44,12 +43,17 @@ import io.objectbox.Box
|
||||
import io.objectbox.kotlin.boxFor
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@AndroidEntryPoint
|
||||
class FoodCollectionActivity : ComponentActivity() {
|
||||
|
||||
private val TAG = "FoodCollectionActivity"
|
||||
companion object {
|
||||
const val TAG = "FoodCollectionActivity"
|
||||
const val MAX_COUNT = 102
|
||||
val PAGE_SIZE = 30
|
||||
}
|
||||
|
||||
private var box: Box<Food>? = null
|
||||
private val collectList: MutableList<FoodCollectionBean> = mutableListOf<FoodCollectionBean>()
|
||||
@@ -57,7 +61,7 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
private lateinit var previewView: PreviewView
|
||||
|
||||
val viewModel: ReceiptViewModel by viewModels()
|
||||
val PAGE_SIZE = 30
|
||||
|
||||
private val cameraUtils: CameraUtils by lazy {
|
||||
CameraUtils(this)
|
||||
}
|
||||
@@ -138,20 +142,8 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
return@setOnClickListener
|
||||
}
|
||||
vectorThread()
|
||||
val goods = searchGoodsList[clickIndex]
|
||||
val files = collectList.filter { it.imageFile!=null }.map { it.imageFile!! }
|
||||
if (files.isEmpty()) {
|
||||
return@setOnClickListener
|
||||
}
|
||||
viewModel.uploadMultipleImages(goods.id!!, goods.goodsName!!, files) {
|
||||
Timber.tag(TAG).d("uploadMultipleImages: ${it}")
|
||||
//{"code":"00000","data":null,"msg":"成功","total":0}
|
||||
val resp = it?.toObject<RespData>()
|
||||
val isSuccess = resp?.code == "00000"
|
||||
binding.ivFinish.run {
|
||||
if (isSuccess) visible() else invisible()
|
||||
}
|
||||
}
|
||||
|
||||
uploadAllImage()
|
||||
}
|
||||
binding.btnTakePhoto.clickWithDebounce {
|
||||
takePhoto()
|
||||
@@ -177,6 +169,10 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
loadEmptyView()
|
||||
|
||||
// binding.tvTitle.setOnClickListener {
|
||||
// uploadImage(goodsImageList[7])
|
||||
// }
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
@@ -210,8 +206,6 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val MAX_COUNT = 100
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun takePhoto() {
|
||||
val count = collectList.count { it.bitmap != null }
|
||||
@@ -250,7 +244,7 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
val index = collectList.indexOfFirst { it.bitmap == null }
|
||||
if (index == -1) {
|
||||
toast("每次只允许保存6条数据")
|
||||
rerurn@ cameraCallback
|
||||
rerurn@cameraCallback
|
||||
}
|
||||
try {
|
||||
ImageUtil.uriToBitmap(this, uri)?.let { bitmap ->
|
||||
@@ -259,12 +253,27 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
targetWidth = 1000, targetHeight = 1300,
|
||||
offsetX = 30, offsetY = 100
|
||||
)
|
||||
initBox()
|
||||
val imageVector = try {
|
||||
FoodModule.bitmap2FloatArray(cropBitmap)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toast("操作失败")
|
||||
return@let
|
||||
}
|
||||
val foodList = FoodModule.queryFoodNameScore(imageVector)
|
||||
val filterList = foodList.filter { it.score < FoodModule.BAG_RATE && it.name.contains("黑袋子")}
|
||||
if (filterList.isNotEmpty()) {
|
||||
toast("当前物品可能被袋子遮挡,请检查后重试")
|
||||
return@let
|
||||
}
|
||||
val file = BitmapSaver.saveToAppFilesDir(
|
||||
cropBitmap, this, "IMG_CROP_${System.currentTimeMillis()}.jpg"
|
||||
)
|
||||
Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}")
|
||||
|
||||
collectList[index].let {
|
||||
it.imageVector = imageVector
|
||||
it.bitmap = cropBitmap
|
||||
it.imageFile = file
|
||||
it.isShowCamera = false
|
||||
@@ -279,9 +288,12 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
private fun vectorThread() {
|
||||
Loading.show(this)
|
||||
Thread {
|
||||
collectList.filter { it.bitmap != null }
|
||||
collectList
|
||||
//.filter { it.bitmap != null }
|
||||
.filter { it.imageVector != null }
|
||||
.forEachIndexed { index, it ->
|
||||
image2VectorTask(it.bitmap!!, index)
|
||||
//image2VectorTask(it.bitmap!!, index)
|
||||
image2VectorTask(imageVector = it.imageVector!!, position = index)
|
||||
}
|
||||
runOnUiThread {
|
||||
window.decorView.postDelayed({
|
||||
@@ -292,16 +304,19 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun image2VectorTask(bitmap: Bitmap, position: Int) {
|
||||
private fun image2VectorTask(
|
||||
bitmap: Bitmap?=null,
|
||||
imageVector: FloatArray?=null,
|
||||
position: Int) {
|
||||
try {
|
||||
initBox()
|
||||
val imageVector = try {
|
||||
FoodModule.bitmap2FloatArray(bitmap)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
//toast("保存失败")
|
||||
return
|
||||
}
|
||||
// val imageVector = try {
|
||||
// FoodModule.bitmap2FloatArray(bitmap)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// //toast("保存失败")
|
||||
// return
|
||||
// }
|
||||
box?.put(
|
||||
Food(
|
||||
name = searchGoodsList[clickIndex].goodsName,
|
||||
@@ -392,9 +407,141 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun uploadAllImage() {
|
||||
val goods = searchGoodsList[clickIndex]
|
||||
val files = collectList.filter { it.imageFile!=null }.map { it.imageFile!! }
|
||||
if (files.isEmpty()) {
|
||||
return
|
||||
}
|
||||
for (index in files.indices step 5) {
|
||||
val end = if(index + 5 < files.size - 1) index + 5 else files.size - 1
|
||||
val list = files.subList(index, end)
|
||||
viewModel.uploadMultipleImages(goods.id!!, goods.goodsName!!, list) {
|
||||
Timber.tag(TAG).d("uploadMultipleImages: ${it}")
|
||||
//{"code":"00000","data":null,"msg":"成功","total":0}
|
||||
// val resp = it?.toObject<RespData>()
|
||||
// val isSuccess = resp?.code == "00000"
|
||||
// binding.ivFinish.run {
|
||||
// if (isSuccess) visible() else invisible()
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class RespData(
|
||||
var code:String?=null,
|
||||
var data:String?=null,
|
||||
var msg:String?=null,
|
||||
)
|
||||
|
||||
|
||||
data class GoodsImage(
|
||||
var goodsId:String,
|
||||
var goodsName:String,
|
||||
var startTime:Long,
|
||||
var endTime:Long
|
||||
)
|
||||
//
|
||||
// val goodsImageList = mutableListOf<GoodsImage>().apply {
|
||||
// add(
|
||||
// GoodsImage(
|
||||
// goodsId = "1986353555971297282",
|
||||
// goodsName = "马铃薯[土豆、洋芋]",
|
||||
// startTime = 1763692477786L,
|
||||
// endTime = 1763693153825L
|
||||
// )
|
||||
// )
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1986607476769869825",
|
||||
// goodsName = "辣椒(青辣椒,螺丝椒)",
|
||||
// startTime = 1763693182929L,
|
||||
// endTime = 1763693621664L
|
||||
// ))
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1987880591453859842",
|
||||
// goodsName = "辣椒(红,小)",
|
||||
// startTime = 1763693683837L,
|
||||
// endTime = 1763694154521L
|
||||
// ))
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1986699063868801025",
|
||||
// goodsName = "鸡腿肉",
|
||||
// startTime = 1763694221267L,
|
||||
// endTime = 1763695052924L
|
||||
// ))
|
||||
//
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1986689570300809217",
|
||||
// goodsName = "猪腿肉",
|
||||
// startTime = 1763695212428L,
|
||||
// endTime = 1763695810578L
|
||||
// ))
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1986673470079029249",
|
||||
// goodsName = "西兰花[绿菜花]",
|
||||
// startTime = 1763695924575L,
|
||||
// endTime = 1763696252669L
|
||||
// ))
|
||||
// add(GoodsImage(
|
||||
// goodsId = "1991473021965070338",
|
||||
// goodsName = "姜[黄姜]",
|
||||
// startTime = 1763696258001L,
|
||||
// endTime = 1763696294831L
|
||||
// ))
|
||||
// add(GoodsImage(
|
||||
// goodsId = "00000",
|
||||
// goodsName = "其它",
|
||||
// startTime = 1763696442577L,
|
||||
// endTime = 1763696990541L
|
||||
// ))
|
||||
// }
|
||||
|
||||
// private fun uploadImage(goodsImage: GoodsImage) {
|
||||
// Loading.show(this)
|
||||
// val cropFile = File(this.cacheDir, "crop")
|
||||
// val list = mutableListOf<File>()
|
||||
// val startTime = goodsImage.startTime
|
||||
// val endTime = goodsImage.endTime
|
||||
// cropFile.listFiles()?.forEach {
|
||||
// if (it.isDirectory) {
|
||||
// return@forEach
|
||||
// }
|
||||
// val start = "IMG_CROP_".length
|
||||
// val end = it.name.indexOf(".jpg")
|
||||
// val time = it.name.substring(start, end).toLong()
|
||||
// if (time in startTime..endTime) {
|
||||
// list.add(it)
|
||||
// }
|
||||
// if (list.size < 5) {
|
||||
// return@forEach
|
||||
// }
|
||||
// viewModel.uploadMultipleImages(
|
||||
// goodsId = goodsImage.goodsId,
|
||||
// goodsName = goodsImage.goodsName,
|
||||
// files = list
|
||||
// ) { data ->
|
||||
// val resp = data?.toObject<RespData>()
|
||||
// val isSuccess = resp?.code == "00000"
|
||||
// binding.ivFinish.run {
|
||||
// if (isSuccess) visible() else invisible()
|
||||
// }
|
||||
// }
|
||||
// list.clear()
|
||||
// }
|
||||
// if (list.isNotEmpty()) {
|
||||
// viewModel.uploadMultipleImages(
|
||||
// goodsId = goodsImage.goodsId,
|
||||
// goodsName = goodsImage.goodsName,
|
||||
// files = list
|
||||
// ) { data ->
|
||||
// val resp = data?.toObject<RespData>()
|
||||
// val isSuccess = resp?.code == "00000"
|
||||
// binding.ivFinish.run {
|
||||
// if (isSuccess) visible() else invisible()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Loading.dismiss()
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -258,7 +258,9 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
Timber.tag(TAG).d("againRecognizeFood,takePhoto异常:${e.message}")
|
||||
e.printStackTrace()
|
||||
Loading.dismiss()
|
||||
recognizeCallback?.invoke(mutableListOf())
|
||||
runOnUiThread {
|
||||
recognizeCallback?.invoke(mutableListOf())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,6 +309,20 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
foodList.forEach {
|
||||
it.name = it.name.split("WP")[0]
|
||||
}
|
||||
val filterList = foodList.filter { it.score < FoodModule.BAG_RATE && it.name.contains("黑袋子")}
|
||||
if (filterList.isNotEmpty()) {
|
||||
runOnUiThread {
|
||||
toast("当前物品可能被袋子遮挡,请检查后重试")
|
||||
if (isAgainRecognize) {
|
||||
Loading.dismiss()
|
||||
recognizeCallback?.invoke(mutableListOf())
|
||||
isAgainRecognize = false
|
||||
return@runOnUiThread
|
||||
}
|
||||
handleGoodsResult(mutableListOf())
|
||||
}
|
||||
return@let
|
||||
}
|
||||
viewModel.recognizeGoodsList(
|
||||
//nameList = foodList,
|
||||
scoreList = foodList,
|
||||
@@ -591,12 +607,26 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
|
||||
private fun recognizeFoodError() {
|
||||
if (isAgainRecognize) {
|
||||
Loading.dismiss()
|
||||
recognizeCallback?.invoke(mutableListOf())
|
||||
runOnUiThread {
|
||||
Loading.dismiss()
|
||||
toast("识别识别,请稍候重试")
|
||||
recognizeCallback?.invoke(mutableListOf())
|
||||
}
|
||||
isAgainRecognize = false
|
||||
} else {
|
||||
handleGoodsResult()
|
||||
}
|
||||
}
|
||||
|
||||
fun uploadImage(goodsId:String, goodsName:String, imageFile: File?) {
|
||||
if (imageFile == null) {
|
||||
return
|
||||
}
|
||||
val list = mutableListOf<File>()
|
||||
list.add(imageFile)
|
||||
viewModel.uploadMultipleImages(goodsId, goodsName, list) {
|
||||
Timber.tag(TAG).d("uploadMultipleImages: ${it}")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import com.sw.inbound.utils.ext.hideKeyboard
|
||||
abstract class BaseDialog(
|
||||
context: Context,
|
||||
var defWidth: Int = 1500.dp,
|
||||
var defHeight: Int = 800.dp
|
||||
var defHeight: Int = 900.dp
|
||||
) : Dialog(context, R.style.DialogTheme) {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -10,6 +10,9 @@ import com.sw.inbound.adapter.RecognizeAdapter
|
||||
import com.sw.inbound.databinding.DialogGoodsRecognizeBinding
|
||||
import com.sw.inbound.databinding.LayoutEmptyRecognizeBinding
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import java.io.File
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@@ -38,7 +41,7 @@ class GoodsRecognizeDialog(
|
||||
|
||||
private val recognizeAdapter by lazy {
|
||||
RecognizeAdapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
// isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
if (list[position].isSelected) {
|
||||
showGoodsStoreDialog(position)
|
||||
@@ -73,9 +76,18 @@ class GoodsRecognizeDialog(
|
||||
it.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
it.adapter = recognizeAdapter
|
||||
}
|
||||
if (recognizeAdapter.list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
val isEmpty = list.isEmpty()
|
||||
if (isEmpty) {
|
||||
// loadEmptyView()
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
} else {
|
||||
binding.rvRecognize.visible()
|
||||
binding.flEmptyLayout.gone()
|
||||
}
|
||||
// if (recognizeAdapter.list.isEmpty()) {
|
||||
// loadEmptyView()
|
||||
// }
|
||||
binding.ivClose.setOnClickListener {
|
||||
dismiss()
|
||||
activity?.delayRecognizeFood()
|
||||
@@ -89,25 +101,38 @@ class GoodsRecognizeDialog(
|
||||
//dismiss()
|
||||
activity?.againRecognizeFood { goodsList ->
|
||||
//binding.rvRecognize.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
list.clear()
|
||||
list.addAll(goodsList)
|
||||
recognizeAdapter.notifyDataSetChanged()
|
||||
if (recognizeAdapter.list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
if (goodsList.isEmpty()) {
|
||||
// loadEmptyView()
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
return@againRecognizeFood
|
||||
}
|
||||
list.clear()
|
||||
list.addAll(goodsList)
|
||||
// recognizeAdapter.isStateViewEnable = false
|
||||
recognizeAdapter.notifyDataSetChanged()
|
||||
|
||||
binding.rvRecognize.visible()
|
||||
binding.flEmptyLayout.gone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyBinding: LayoutEmptyRecognizeBinding? = null
|
||||
// private var emptyBinding: LayoutEmptyRecognizeBinding? = null
|
||||
private fun loadEmptyView() {
|
||||
if (emptyBinding == null) {
|
||||
emptyBinding = LayoutEmptyRecognizeBinding.inflate(inflater, binding.rvRecognize, false)
|
||||
}
|
||||
emptyBinding?.root?.let {
|
||||
recognizeAdapter.stateView = it
|
||||
}
|
||||
// if (emptyBinding == null) {
|
||||
// emptyBinding = LayoutEmptyRecognizeBinding.inflate(inflater, binding.flEmptyLayout, false)
|
||||
// }
|
||||
// binding.flEmptyLayout.removeAllViews()
|
||||
// emptyBinding?.root.let {
|
||||
// binding.flEmptyLayout.addView(it)
|
||||
// }
|
||||
binding.rvRecognize.gone()
|
||||
binding.flEmptyLayout.visible()
|
||||
// emptyBinding?.root?.let {
|
||||
// recognizeAdapter.isStateViewEnable = true
|
||||
// recognizeAdapter.stateView = it
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.sw.inbound.utils.removeTrailingZeros
|
||||
import io.objectbox.Box
|
||||
import io.objectbox.kotlin.boxFor
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import kotlin.Int
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.min
|
||||
@@ -322,6 +323,7 @@ class GoodsStoreDialog(
|
||||
}
|
||||
val id = binding.tvProcurementUnit.tag.toString()
|
||||
val unitVo = goods.unitVoList!!.first { it.businessUnitId == id }
|
||||
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
|
||||
confirmBlock(
|
||||
GoodsInfo(
|
||||
goodId = goods.id,
|
||||
@@ -429,7 +431,7 @@ class GoodsStoreDialog(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var imageFile: File?=null
|
||||
private var box: Box<Food>? = null
|
||||
private fun collectGoodsVector() {
|
||||
try {
|
||||
@@ -444,6 +446,7 @@ class GoodsStoreDialog(
|
||||
val file = BitmapSaver.saveToAppFilesDir(
|
||||
cropBitmap, context, "IMG_CROP_${System.currentTimeMillis()}.jpg"
|
||||
)
|
||||
imageFile = file
|
||||
Timber.d("${this.javaClass.simpleName}-collectGoodsVector-裁剪bitmap保存文件路径:${file?.absolutePath}")
|
||||
if (box == null) {
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
|
||||
@@ -29,9 +29,11 @@ object FoodModule {
|
||||
private lateinit var embeddingsList: List<List<Float>>
|
||||
private lateinit var labelsList: IntArray
|
||||
private lateinit var classInfo: FoodClassInfo
|
||||
val NO_MEAN_RGB = floatArrayOf(0.0f, 0.0f, 0.0f)
|
||||
val NO_STD_RGB = floatArrayOf(1.0f, 1.0f, 1.0f)
|
||||
val DEFAULT_FOOD_INDEX = -1
|
||||
private val NO_MEAN_RGB = floatArrayOf(0.0f, 0.0f, 0.0f)
|
||||
private val NO_STD_RGB = floatArrayOf(1.0f, 1.0f, 1.0f)
|
||||
const val DEFAULT_FOOD_INDEX = -1
|
||||
|
||||
const val BAG_RATE = 0.05
|
||||
|
||||
fun init(context: Context) {
|
||||
Thread {
|
||||
@@ -40,9 +42,9 @@ object FoodModule {
|
||||
//if (box.all.isNotEmpty()) {
|
||||
// box.removeAll()
|
||||
//}
|
||||
//if (box.all.isEmpty()) {
|
||||
// initDefFoodData(context)
|
||||
//}
|
||||
if (box.all.isEmpty()) {
|
||||
initDefFoodData(context)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ object FoodModule {
|
||||
return emptyList()
|
||||
}
|
||||
val maxScoreList = nameScoreList
|
||||
.filter { it.score < 0.20 }
|
||||
.filter { it.score < 0.15 }
|
||||
.groupBy { it.name }
|
||||
.map { (_, value) -> value.minByOrNull { it.score }!! }
|
||||
.toMutableList()
|
||||
|
||||
@@ -27,7 +27,7 @@ object BitmapSaver {
|
||||
context: Context,
|
||||
fileName: String,
|
||||
format: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
|
||||
quality: Int = 10
|
||||
quality: Int = 100
|
||||
): File? {
|
||||
//val dir = context.getExternalFilesDir(null)
|
||||
val dir = context.cacheDir
|
||||
|
||||
@@ -9,11 +9,13 @@ object ImageUtil {
|
||||
fun uriToBitmap(context: Context, uri: Uri): Bitmap? {
|
||||
return try {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inSampleSize = 2; // 这会将图片的尺寸缩小到原来的1/2
|
||||
//options.inSampleSize = 2; // 这会将图片的尺寸缩小到原来的1/2
|
||||
options.inJustDecodeBounds = false
|
||||
// options.inPreferredConfig = Bitmap.Config.ARGB_8888
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565
|
||||
context.contentResolver.openInputStream(uri)?.use { stream ->
|
||||
BitmapFactory.decodeStream(stream, null, options)
|
||||
// BitmapFactory.decodeStream(stream, null, options)
|
||||
BitmapFactory.decodeStream(stream)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
||||
@@ -27,23 +27,57 @@
|
||||
android:textColor="#ff141428"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/rvRecognize"
|
||||
app:layout_constraintBottom_toTopOf="@+id/flContent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvRecognize"
|
||||
android:layout_width="wrap_content"
|
||||
<FrameLayout
|
||||
android:id="@+id/flContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="340dp"
|
||||
android:layout_marginTop="180dp"
|
||||
tools:itemCount="5"
|
||||
android:layout_marginHorizontal="30dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:overScrollMode="never"
|
||||
android:layout_marginHorizontal="30dp"
|
||||
tools:listitem="@layout/list_item_recognize"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_marginTop="180dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvRecognize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
tools:itemCount="5"
|
||||
android:overScrollMode="never"
|
||||
tools:listitem="@layout/list_item_recognize" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/flEmptyLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone"
|
||||
tools:ignore="HardcodedText,UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="80dp"
|
||||
android:src="@mipmap/ic_tip_warn"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="50dp"
|
||||
android:text="识别失败,请稍后重试!"
|
||||
android:textColor="#ff000000"
|
||||
android:textSize="36sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/dividerLine"
|
||||
|
||||
@@ -13,10 +13,13 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toast_tv"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="90dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
android:maxLines="3"
|
||||
android:minWidth="300dp"
|
||||
android:maxWidth="420dp"
|
||||
android:paddingVertical="15dp"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="26sp"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center"
|
||||
tools:ignore="HardcodedText,UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
|
||||
Reference in New Issue
Block a user