Remove useless code
This commit is contained in:
@@ -43,8 +43,6 @@ class ImageSegmentationService(private val context: Context) {
|
||||
|
||||
private var interpreter: Interpreter? = null
|
||||
|
||||
private val coloredLabels: List<ColoredLabel> = coloredLabels()
|
||||
|
||||
suspend fun initialize() {
|
||||
interpreter = try {
|
||||
val litertBuffer = FileUtil.loadMappedFile(context, "deeplab_v3.tflite")
|
||||
@@ -112,9 +110,7 @@ class ImageSegmentationService(private val context: Context) {
|
||||
.build()
|
||||
val maskImage = TensorImage()
|
||||
maskImage.load(mask, imageProperties)
|
||||
return Segmentation(
|
||||
listOf(maskImage), coloredLabels
|
||||
)
|
||||
return Segmentation(listOf(maskImage))
|
||||
}
|
||||
|
||||
private fun processImage(inferenceData: InferenceData): ByteBuffer {
|
||||
@@ -139,60 +135,11 @@ class ImageSegmentationService(private val context: Context) {
|
||||
|
||||
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(
|
||||
val masks: List<TensorImage>,
|
||||
val coloredLabels: List<ColoredLabel>,
|
||||
val masks: List<TensorImage>
|
||||
)
|
||||
|
||||
data class ColoredLabel(val label: String, val displayName: String, val argb: Int)
|
||||
|
||||
data class SegmentationResult(
|
||||
val segmentation: Segmentation,
|
||||
val inferenceTime: Long
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.mydomain.myscan
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import org.mydomain.myscan.ui.theme.MyScanTheme
|
||||
import org.mydomain.myscan.view.CameraScreen
|
||||
@@ -32,7 +29,6 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
Log.d("MyScan", "!!"+uiState.toString())
|
||||
MyScanTheme {
|
||||
Scaffold { innerPadding ->
|
||||
Column {
|
||||
@@ -50,15 +46,12 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
@Composable
|
||||
fun MyMessageBox(msg: String?, inferenceTime: Long) {
|
||||
Log.d("MyScan", "MyMessageBox recompose: $msg")
|
||||
Text(
|
||||
text = (msg ?: "") + " inferred in " + inferenceTime + "ms",
|
||||
text = (msg ?: "") + " / inferred in " + inferenceTime + "ms",
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.background(Color.Yellow)
|
||||
.fillMaxWidth(),
|
||||
color = Color.Black,
|
||||
fontSize = 20.sp
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MainViewModel(private val imageSegmentationService: ImageSegmentationService): ViewModel() {
|
||||
|
||||
Reference in New Issue
Block a user