Enhance YUV Data Image Resolution in MSDK-v5.9
已完成Hello everyone, a few months ago I asked how to extract the bitmap from the image captured in real-time from the drone using the 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 the image and continued with the project. However, I would like to improve the quality of the extracted image. Is it possible to do this via code? If there is a way, could you show me a code example?
The images extracted from YUV data, converted to bitmap, and saved as JPG, are approximately 700kb in size.
The challenge I'm facing is that we need to read QR codes of 1.6 cm x 1.6 cm or 2.5 cm x 2.5 cm with the drone, and for this, I need to improve the image quality to a higher resolution (HD, FullHD, etc.). This would allow me to pass the bitmap to a QR code extractor from 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
}
-
Dear developers, Hello, thank you for contacting DJI Innovation. Are you referring to the blurriness of the image after the YUV data has undergone processing? Regarding data processing, the MSDK only provides a reference method; other processing methods need to be implemented by you. I hope our solution can help you, thank you for your email, wish you a happy life! Best Regards, Dji innovation SDK technical support
请先登录再写评论。
评论
1 条评论