替换模型
This commit is contained in:
@@ -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,69 +354,80 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
var isShowRecognizeDialog = true
|
||||
|
||||
private suspend fun readBitmap(bitmap: Bitmap) {
|
||||
// binding.imageView.setImageBitmap(bitmap)
|
||||
val file = BitmapSaver.saveToAppFilesDir(
|
||||
bitmap,
|
||||
this,
|
||||
"IMG_CROP_${System.currentTimeMillis()}.jpg"
|
||||
)
|
||||
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(bitmap)
|
||||
if (bitmap.isRecycled.not()) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
// if (newBmp.isRecycled.not()) {
|
||||
// newBmp.recycle()
|
||||
// }
|
||||
// val count = foodList.count { it.score < 0.15 }
|
||||
val count = foodList.size
|
||||
if (count == 0) {
|
||||
//未识别到满足相似度>=0.85的,显示识别率最高的
|
||||
var tempList = foodList.filter { it.name.contains("黑袋子").not() }
|
||||
if (tempList.isEmpty()) {
|
||||
recognizeFoodError()
|
||||
return
|
||||
}
|
||||
tempList = tempList.subList(0, 1)
|
||||
tempList.forEach { it.name = it.name.split("WP")[0] }
|
||||
recognizeGoodsList(tempList)
|
||||
return
|
||||
}
|
||||
//if (foodList.isEmpty()) {
|
||||
// recognizeFoodError()
|
||||
// return@let
|
||||
//}
|
||||
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
|
||||
}
|
||||
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
|
||||
)
|
||||
// val file = BitmapSaver.saveToAppFilesDir(
|
||||
// newBmp,
|
||||
// this,
|
||||
// "IMG_CROP_${System.currentTimeMillis()}.jpg"
|
||||
// )
|
||||
// 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)
|
||||
if (bitmap.isRecycled.not()) {
|
||||
bitmap.recycle()
|
||||
}
|
||||
if (newBmp.isRecycled.not()) {
|
||||
newBmp.recycle()
|
||||
}
|
||||
// val count = foodList.count { it.score < 0.15 }
|
||||
val count = foodList.size
|
||||
if (count == 0) {
|
||||
//未识别到满足相似度>=0.85的,显示识别率最高的
|
||||
var tempList = foodList.filter { it.name.contains("黑袋子").not() }
|
||||
if (tempList.isEmpty()) {
|
||||
recognizeFoodError()
|
||||
return@let
|
||||
}
|
||||
tempList = tempList.subList(0, 1)
|
||||
tempList.forEach { it.name = it.name.split("WP")[0] }
|
||||
recognizeGoodsList(tempList)
|
||||
return@let
|
||||
}
|
||||
//if (foodList.isEmpty()) {
|
||||
// recognizeFoodError()
|
||||
// return@let
|
||||
//}
|
||||
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
|
||||
}
|
||||
recognizeGoodsList(foodList)
|
||||
readBitmap(newBmp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +809,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun logInfo(msg:String) {
|
||||
private fun logInfo(msg: String) {
|
||||
Timber.tag(TAG).d(msg)
|
||||
LogSaveUtil.saveLogFile(msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user