Improve YUV data image received resolution on MSDK-v5.9
已完成Hello everyone, a few months ago I asked you how to extract the bitmap from the image captured in real time from the drone using YUV data listener. Post: https://sdk-forum.dji.net/hc/en-us/community/posts/25059494247449-FPVWidget-get-Bitmap-in-MSDK-V5
It worked, I managed to extract it here and continued, however I would like to improve the quality of the extracted image, is this possible by code? If there is any way, could you show me a code example?
Images extracted from YUV data converted to bitmap and saved as JPG are approximately 700kb in size.
I would really need a way to improve the quality of these images to a higher resolution (HD, FullHD etc) so that I can pass the bitmap to an extractor of the QRCodes present in the image.
The drone: Mavic 3 Enterprise
Code to extract YUV Data:
fun getBitmap(callback: FPVWidgetBitmapCallback): Bitmap? {
var bitmap: Bitmap? = null
if (videoDecoderYuv == null) return null
videoDecoderYuv!!.addYuvDataListener(object : YuvDataListener {
override fun onReceive(
mediaFormat: MediaFormat?,
data: ByteArray?,
width: Int,
height: Int
) {
// This value may be increased if the photos come in the wrong color
if (++block == 10) {
block = 0
data?.let {
AsyncTask.execute {
val yuvImage = YuvImage(prepareYuvDataToJPEG420P(data, width, height),
ImageFormat.NV21, width, height, null)
val out = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, width, height), 100, out)
val imageBytes = out.toByteArray()
bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
callback.onReceive(bitmap)
out.close()
}
}
videoDecoderYuv!!.removeYuvDataListener(this)
}
}
})
return bitmap
}
private fun prepareYuvDataToJPEG420P(yuvFrame: ByteArray, width: Int, height: Int): ByteArray {
if (yuvFrame.size < width * height) {
return yuvFrame
}
val length = width * height
val u = ByteArray(width * height / 4)
val v = ByteArray(width * height / 4)
for (i in u.indices) {
u[i] = yuvFrame[length + i]
v[i] = yuvFrame[length + u.size + i]
}
for (i in u.indices) {
yuvFrame[length + 2 * i] = v[i]
yuvFrame[length + 2 * i + 1] = u[i]
}
return yuvFrame
}
-
Sorry, but we do not have any guidance documents regarding YUV data processing. If you are considering using other interfaces, you may refer to the methods mentioned in this issue to generate photo files; however, there are currently no reference methods for modifying the resolution. https://sdk-forum.dji.net/hc/zh-cn/community/posts/33709871608089
请先登录再写评论。
评论
4 条评论