向相机询问I420 YUV420框架或在Kotlin上将NV21转换为I420框架的方法

问题描述

我正在使用相机的imageAnalyzer并获得NV21框架,但我需要I420框架。有什么办法可以要求I420帧或将NV21转换为I420?在libyuv中,几乎看不到任何api,但这是在C ++中,我将只需要为一个api编写JNI并将libyub与应用程序一起打包,该解决方案对我不利。

这是我的分析仪:

    private class LuminosityAnalyzer(private val listener: LumaListener) : ImageAnalysis.Analyzer {

        private fun ByteBuffer.toByteArray(): ByteArray {
            rewind()    // Rewind the buffer to zero
            val data = ByteArray(remaining())
            get(data)   // Copy the buffer into a byte array
            return data // Return the byte array
        }

        override fun analyze(image: ImageProxy) {

            val buffer = image.planes[0].buffer
            Log.d(TAG,"analyze: y size = ${image.planes[0].buffer.remaining()} u size = ${image.planes[1].buffer.remaining()} v size = ${image.planes[2].buffer.remaining()}")
            val data = buffer.toByteArray()
            val pixels = data.map { it.toInt() and 0xFF }
            val luma = pixels.average()
            Log.d(TAG,"analyze: TarunD image format width =  ${image.planes[0].pixelStride} ${image.planes[0].rowStride} height = ${image.height} u width = ${image.planes[2].rowStride} height = ${image.planes[2]}")
            listener(luma)

            image.close()
        }
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...