diff --git a/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt b/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt index fc95ae0..de1c140 100644 --- a/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt +++ b/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt @@ -1,14 +1,16 @@ package com.casic.br.app.utils -import com.casic.br.app.callback.OnYoloResultSiftCallback import com.casic.br.app.extensions.isContains import com.casic.br.app.external.YoloResult import com.casic.br.app.model.HiddenTroubleResult -class YoloTargetDetectHelper(private val callback: OnYoloResultSiftCallback) { +class YoloTargetDetectHelper { private val kTag = "YoloTargetDetectHelper" - private val hiddenTroubles = ArrayList() + + @JvmField + @Volatile + var hiddenTroubles = ArrayList() fun siftHiddenTrouble( segmentationResults: MutableList, detectResults: MutableList @@ -17,14 +19,6 @@ "有限空间作业" -> { //结果包含人 if (detectResults.isContains(3)) { - if (!detectResults.isContains(20) && !detectResults.isContains(15)) { - //不包含工服且未戴安全帽 - val result = HiddenTroubleResult() - result.alarmCode = "ConfinedSpaceHasNoWorkerClothes" - result.warning = "未穿工服和未佩戴安全帽" - hiddenTroubles.add(result) - } - if (!detectResults.isContains(20) || !detectResults.isContains(8)) { //不包含工服/防护服 val result = HiddenTroubleResult() @@ -166,7 +160,7 @@ if (detectResults.isContains(49)) { val result = HiddenTroubleResult() - result.alarmCode = "NonStandardHoses" + result.alarmCode = "NonResidentUserHasNonDedicatedHose" result.warning = "非标准软管" hiddenTroubles.add(result) } @@ -183,7 +177,7 @@ if (!detectResults.isContains(22)) { //不包含燃气泄漏报警装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" + result.alarmCode = "NonResidentUserHasNoAlarmDevice" result.warning = "无燃气泄漏报警装置" hiddenTroubles.add(result) } @@ -199,8 +193,8 @@ if (!detectResults.isContains(34)) { //不包含熄火保护装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoFlameoutProtection" - result.warning = "未发现熄火保护" + result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" + result.warning = "未发现熄火保护装置" hiddenTroubles.add(result) } } @@ -209,8 +203,8 @@ "居民用户" -> { if (detectResults.isContains(49)) { val result = HiddenTroubleResult() - result.alarmCode = "NonStandardHoses" - result.warning = "发现非标准软管" + result.alarmCode = "NonResidentUserHasNonDedicatedHose" + result.warning = "非标准软管" hiddenTroubles.add(result) } @@ -226,15 +220,12 @@ if (!detectResults.isContains(34)) { //不包含熄火保护装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoFlameoutProtection" + result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" result.warning = "未发现熄火保护" hiddenTroubles.add(result) } } } } - - //结果统一回调 - callback.onResultSifted(hiddenTroubles) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt b/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt index fc95ae0..de1c140 100644 --- a/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt +++ b/app/src/main/java/com/casic/br/app/utils/YoloTargetDetectHelper.kt @@ -1,14 +1,16 @@ package com.casic.br.app.utils -import com.casic.br.app.callback.OnYoloResultSiftCallback import com.casic.br.app.extensions.isContains import com.casic.br.app.external.YoloResult import com.casic.br.app.model.HiddenTroubleResult -class YoloTargetDetectHelper(private val callback: OnYoloResultSiftCallback) { +class YoloTargetDetectHelper { private val kTag = "YoloTargetDetectHelper" - private val hiddenTroubles = ArrayList() + + @JvmField + @Volatile + var hiddenTroubles = ArrayList() fun siftHiddenTrouble( segmentationResults: MutableList, detectResults: MutableList @@ -17,14 +19,6 @@ "有限空间作业" -> { //结果包含人 if (detectResults.isContains(3)) { - if (!detectResults.isContains(20) && !detectResults.isContains(15)) { - //不包含工服且未戴安全帽 - val result = HiddenTroubleResult() - result.alarmCode = "ConfinedSpaceHasNoWorkerClothes" - result.warning = "未穿工服和未佩戴安全帽" - hiddenTroubles.add(result) - } - if (!detectResults.isContains(20) || !detectResults.isContains(8)) { //不包含工服/防护服 val result = HiddenTroubleResult() @@ -166,7 +160,7 @@ if (detectResults.isContains(49)) { val result = HiddenTroubleResult() - result.alarmCode = "NonStandardHoses" + result.alarmCode = "NonResidentUserHasNonDedicatedHose" result.warning = "非标准软管" hiddenTroubles.add(result) } @@ -183,7 +177,7 @@ if (!detectResults.isContains(22)) { //不包含燃气泄漏报警装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" + result.alarmCode = "NonResidentUserHasNoAlarmDevice" result.warning = "无燃气泄漏报警装置" hiddenTroubles.add(result) } @@ -199,8 +193,8 @@ if (!detectResults.isContains(34)) { //不包含熄火保护装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoFlameoutProtection" - result.warning = "未发现熄火保护" + result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" + result.warning = "未发现熄火保护装置" hiddenTroubles.add(result) } } @@ -209,8 +203,8 @@ "居民用户" -> { if (detectResults.isContains(49)) { val result = HiddenTroubleResult() - result.alarmCode = "NonStandardHoses" - result.warning = "发现非标准软管" + result.alarmCode = "NonResidentUserHasNonDedicatedHose" + result.warning = "非标准软管" hiddenTroubles.add(result) } @@ -226,15 +220,12 @@ if (!detectResults.isContains(34)) { //不包含熄火保护装置 val result = HiddenTroubleResult() - result.alarmCode = "NonResidentUserHasNoFlameoutProtection" + result.alarmCode = "NonResidentUserHasNoStoveFlameoutProtection" result.warning = "未发现熄火保护" hiddenTroubles.add(result) } } } } - - //结果统一回调 - callback.onResultSifted(hiddenTroubles) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/app/view/StartCheckByYoloActivity.kt b/app/src/main/java/com/casic/br/app/view/StartCheckByYoloActivity.kt index d31ee12..512feeb 100644 --- a/app/src/main/java/com/casic/br/app/view/StartCheckByYoloActivity.kt +++ b/app/src/main/java/com/casic/br/app/view/StartCheckByYoloActivity.kt @@ -14,7 +14,6 @@ import androidx.lifecycle.lifecycleScope import com.amap.api.location.AMapLocation import com.casic.br.app.R -import com.casic.br.app.callback.OnYoloResultSiftCallback import com.casic.br.app.databinding.ActivityStartCheckByYoloBinding import com.casic.br.app.extensions.convert2YoloResult import com.casic.br.app.extensions.getSceneByTarget @@ -51,12 +50,11 @@ import org.opencv.core.Mat import org.opencv.osgi.OpenCVNativeLoader import java.io.File -import java.util.Stack import java.util.Timer import java.util.TimerTask class StartCheckByYoloActivity : KotlinBaseActivity(), - SurfaceHolder.Callback, INativeCallback, Handler.Callback, OnYoloResultSiftCallback { + SurfaceHolder.Callback, INativeCallback, Handler.Callback { private val kTag = "StartCheckActivity" private val context = this @@ -67,8 +65,7 @@ private val mat by lazy { Mat() } private val weakReferenceHandler by lazy { WeakReferenceHandler(this) } private val detectResultDialog by lazy { DetectResultDialog(this) } - private val detectHelper by lazy { YoloTargetDetectHelper(this) } - private val troubleSiftCacheStack by lazy { Stack>() } + private val detectHelper by lazy { YoloTargetDetectHelper() } private lateinit var inspectionViewModel: InspectionViewModel private lateinit var configViewModel: ConfigViewModel private lateinit var imageFileViewModel: ImageFileViewModel @@ -121,7 +118,7 @@ } configViewModel = ViewModelProvider(this)[ConfigViewModel::class.java] - configViewModel.getDictionaryByCode(context, "pitfallBigType") + configViewModel.getDictionaryByCode(this, "pitfallBigType") configViewModel.dictionary.observe(this) { if (it.code == 200) { RuntimeCache.mainDicModels = it.data @@ -131,7 +128,7 @@ alarmViewModel = ViewModelProvider(this)[AlarmViewModel::class.java] alarmViewModel.resultModel.observe(this) { if (it == 200) { - "提交成功".show(context) + "提交成功".show(this) detectedTargetSet.add(result.warning) } } @@ -140,9 +137,7 @@ imageFileViewModel.resultModel.observe(this) { if (it.code == 200) { //报警图片提交成功后,提交隐患 - alarmViewModel.uploadDetectTargetAlarm( - context, result.alarmCode, it.data.toString() - ) + alarmViewModel.uploadDetectTargetAlarm(this, result.alarmCode, it.data.toString()) } } @@ -150,23 +145,19 @@ timer = Timer() timer.schedule(object : TimerTask() { override fun run() { - if (troubleSiftCacheStack.isNotEmpty()) { - //筛选出没有添加过的隐患 - val temp = ArrayList() - troubleSiftCacheStack.pop().forEach { - if (!detectedTargetSet.contains(it.warning)) { - temp.add(it) - } - } - if (temp.isNotEmpty()) { + val lastResult = detectHelper.hiddenTroubles + //筛选出没有添加过的隐患 + for (res in lastResult) { + if (!detectedTargetSet.contains(res.warning)) { val message = weakReferenceHandler.obtainMessage() message.what = 2024092601 - message.obj = temp.first() + message.obj = res weakReferenceHandler.sendMessage(message) + break } } } - }, 1000, 10 * 1000L) + }, 1000, 5 * 1000L) } override fun initEvent() { @@ -360,15 +351,6 @@ weakReferenceHandler.sendMessage(message) } - override fun onResultSifted(results: List) { - if (results.isEmpty()) { - return - } - - //将隐患结果一帧一帧的缓存 - troubleSiftCacheStack.push(results) - } - override fun handleMessage(msg: Message): Boolean { when (msg.what) { 2024082901 -> { @@ -403,18 +385,18 @@ 2024092601 -> { if (!detectResultDialog.isShowing) { - val hiddenTroubleResult = msg.obj as HiddenTroubleResult - //显示差集的隐患 + val result = msg.obj as HiddenTroubleResult if (mat.width() > 0 || mat.height() > 0) { - detectResultDialog.updateDialogContentView(hiddenTroubleResult, mat, + detectResultDialog.updateDialogContentView(result, mat, object : DetectResultDialog.OnDialogButtonClickListener { override fun onConfirmClick( file: File, result: HiddenTroubleResult ) { - this@StartCheckByYoloActivity.result = hiddenTroubleResult + this@StartCheckByYoloActivity.result = result imageFileViewModel.uploadImage(file) } - }).show() + } + ).show() } } }