Remove useless code

This commit is contained in:
Pierre-Yves Nicolas
2025-05-25 22:38:00 +02:00
parent 6f68bf05d6
commit f8f1f6bab2
3 changed files with 3 additions and 64 deletions

View File

@@ -43,8 +43,6 @@ class ImageSegmentationService(private val context: Context) {
private var interpreter: Interpreter? = null private var interpreter: Interpreter? = null
private val coloredLabels: List<ColoredLabel> = coloredLabels()
suspend fun initialize() { suspend fun initialize() {
interpreter = try { interpreter = try {
val litertBuffer = FileUtil.loadMappedFile(context, "deeplab_v3.tflite") val litertBuffer = FileUtil.loadMappedFile(context, "deeplab_v3.tflite")
@@ -112,9 +110,7 @@ class ImageSegmentationService(private val context: Context) {
.build() .build()
val maskImage = TensorImage() val maskImage = TensorImage()
maskImage.load(mask, imageProperties) maskImage.load(mask, imageProperties)
return Segmentation( return Segmentation(listOf(maskImage))
listOf(maskImage), coloredLabels
)
} }
private fun processImage(inferenceData: InferenceData): ByteBuffer { private fun processImage(inferenceData: InferenceData): ByteBuffer {
@@ -139,60 +135,11 @@ class ImageSegmentationService(private val context: Context) {
return mask return mask
} }
private fun coloredLabels(): List<ColoredLabel> {
val labels = listOf(
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
"car",
"cat",
"chair",
"cow",
"dining table",
"dog",
"horse",
"motorbike",
"person",
"potted plant",
"sheep",
"sofa",
"train",
"tv",
"------"
)
val colors = MutableList(labels.size) {
ColoredLabel(
labels[0], "", Color.BLACK
)
}
val random = Random()
val goldenRatioConjugate = 0.618033988749895
var hue = random.nextDouble()
// Skip the first label as it's already assigned black
for (idx in 1 until labels.size) {
hue += goldenRatioConjugate
hue %= 1.0
// Adjust saturation & lightness as needed
val color = Color.HSVToColor(floatArrayOf(hue.toFloat() * 360, 0.7f, 0.8f))
colors[idx] = ColoredLabel(labels[idx], "", color)
}
return colors
}
data class Segmentation( data class Segmentation(
val masks: List<TensorImage>, val masks: List<TensorImage>
val coloredLabels: List<ColoredLabel>,
) )
data class ColoredLabel(val label: String, val displayName: String, val argb: Int)
data class SegmentationResult( data class SegmentationResult(
val segmentation: Segmentation, val segmentation: Segmentation,
val inferenceTime: Long val inferenceTime: Long

View File

@@ -1,12 +1,10 @@
package org.mydomain.myscan package org.mydomain.myscan
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@@ -19,7 +17,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mydomain.myscan.ui.theme.MyScanTheme import org.mydomain.myscan.ui.theme.MyScanTheme
import org.mydomain.myscan.view.CameraScreen import org.mydomain.myscan.view.CameraScreen
@@ -32,7 +29,6 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge() enableEdgeToEdge()
setContent { setContent {
val uiState by viewModel.uiState.collectAsStateWithLifecycle() val uiState by viewModel.uiState.collectAsStateWithLifecycle()
Log.d("MyScan", "!!"+uiState.toString())
MyScanTheme { MyScanTheme {
Scaffold { innerPadding -> Scaffold { innerPadding ->
Column { Column {
@@ -50,15 +46,12 @@ class MainActivity : ComponentActivity() {
@Composable @Composable
fun MyMessageBox(msg: String?, inferenceTime: Long) { fun MyMessageBox(msg: String?, inferenceTime: Long) {
Log.d("MyScan", "MyMessageBox recompose: $msg")
Text( Text(
text = (msg ?: "") + " inferred in " + inferenceTime + "ms", text = (msg ?: "") + " / inferred in " + inferenceTime + "ms",
modifier = Modifier modifier = Modifier
.padding(16.dp) .padding(16.dp)
.background(Color.Yellow)
.fillMaxWidth(), .fillMaxWidth(),
color = Color.Black, color = Color.Black,
fontSize = 20.sp
) )
} }

View File

@@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class MainViewModel(private val imageSegmentationService: ImageSegmentationService): ViewModel() { class MainViewModel(private val imageSegmentationService: ImageSegmentationService): ViewModel() {