在jetpack compose中观察tensorflow的结果

问题描述 投票:0回答:0

我正在创建一个使用 jetpack compose 和 tensorflow 检测对象的应用程序。然而,结果只执行一次,我希望它在每次相机运行时都执行。

LaunchedEffect(lensFacing) {
    val cameraProvider = context.getCameraProvider()
    val imageAnalysis = ImageAnalysis.Builder()
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
        .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_RGBA_8888)
        .build()

    imageAnalysis.setAnalyzer(cameraExecutor) { imageProxy ->
        image = imageProxy.image

        val imageRotation = imageProxy.imageInfo.rotationDegrees

        if (image != null) {

            bitmapBuffer = Bitmap.createBitmap(
                image!!.width,
                image!!.height,
                Bitmap.Config.ARGB_8888
            )

            image.use { bitmapBuffer?.copyPixelsFromBuffer(image!!.planes[0].buffer) }

            val imageProcessor =
                ImageProcessor.Builder()
                    .add(Rot90Op(-imageRotation / 90))
                    .build()
            tensorImage = imageProcessor.process(TensorImage.fromBitmap(bitmapBuffer))
            val results = objectDetector.detect(tensorImage)


            Log.e("TEST", results.toString())

        }
    }

    cameraProvider.unbindAll()
    camera = cameraProvider.bindToLifecycle(
        lifecycleOwner,
        cameraSelector,
        imageAnalysis,
        preview,
        imageCapture
    )

    preview.setSurfaceProvider(previewView.surfaceProvider)
}

日志只显示一次,我希望它在每次相机运行时执行。谢谢

android tensorflow android-jetpack-compose tensorflow-lite
© www.soinside.com 2019 - 2024. All rights reserved.