Я хотел создать мобильное приложение с использованием Kotlin, Tensorflow Lite и Android Studio, но у меня возникли проблемы с распаковкой результатов из модели распознавания объектов Tensorflow. Кроме того, location.get() выделен красным. Кажется, я инициализировал все важные библиотеки.
Пожалуйста, помогите мне с этим. Заранее спасибо за ответы!
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {
bitmap = textureView.bitmap!!
var image = TensorImage.fromBitmap(bitmap)
image = imageProcessor.process(image)
val outputs = model.process(image)
val detectionResult = outputs.detectionResultList.get(0)
val locations = detectionResult.locationAsRectF;
val classes = detectionResult.categoryAsString;
val scores = detectionResult.scoreAsFloat
var mutable = bitmap.copy(Bitmap.Config.ARGB_8888, true)
var canvas = Canvas(mutable)
var x = 0
val h = mutable.height
val w = mutable.width
paint.textSize = h/15f
paint.strokeWidth = h/85f
scores.forEachIndexed {index, fl ->
x = index
x *= 4
if(fl > 0.5){
paint.setColor(colors.get(index))
paint.style = Paint.Style.STROKE
canvas.drawRect(
RectF(
locations.get(x + 1) * w,
locations.get(x) * h,
locations.get(x + 3) * w,
locations.get(x + 2) * h
), paint)
paint.style = Paint.Style.FILL
canvas.drawText(labels.get(classes.get(index).toInt())+" "+fl.toString(), locations.get(x+1)*w, locations.get(x)*h, paint)
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... the-onsurf