Fix computation of the number of objects that are detected
This commit is contained in:
@@ -32,7 +32,7 @@ class MainViewModel(private val imageSegmentationService: ImageSegmentationServi
|
|||||||
imageSegmentationService.initialize()
|
imageSegmentationService.initialize()
|
||||||
imageSegmentationService.segmentation
|
imageSegmentationService.segmentation
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.map { UiState("Found ${it.segmentation.masks.size} objects!", it.inferenceTime) }
|
.map { UiState("Found ${numberOfObjectsDetected(it.segmentation)} objects!", it.inferenceTime) }
|
||||||
.collect {
|
.collect {
|
||||||
Log.d("MyScan", "New UIstate ${it}")
|
Log.d("MyScan", "New UIstate ${it}")
|
||||||
_uiState.value = it
|
_uiState.value = it
|
||||||
@@ -40,6 +40,15 @@ class MainViewModel(private val imageSegmentationService: ImageSegmentationServi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun numberOfObjectsDetected(segmentation: ImageSegmentationService.Segmentation) : Int {
|
||||||
|
val tensor = segmentation.masks[0];
|
||||||
|
val buffer = tensor.buffer
|
||||||
|
val uniqueValues = HashSet<Int>()
|
||||||
|
for (i in 0..tensor.width * tensor.height - 1) {
|
||||||
|
uniqueValues.add(buffer[i].toInt())
|
||||||
|
}
|
||||||
|
return uniqueValues.size - 1;
|
||||||
|
}
|
||||||
|
|
||||||
fun segment(imageProxy: ImageProxy) {
|
fun segment(imageProxy: ImageProxy) {
|
||||||
Log.d("MyScan", "MainViewModel.Calling segment")
|
Log.d("MyScan", "MainViewModel.Calling segment")
|
||||||
|
|||||||
Reference in New Issue
Block a user