QuickBirdEng / yuvToMat

High-performance library for converting YUV_420_888 Android Camera images to OpenCV RGB Mats
53 stars 13 forks source link

UnsupportedImageFormatException #5

Open gordinmitya opened 4 years ago

gordinmitya commented 4 years ago

Yuv format is not supported: Yuv(resource=androidx.camera.core.SettableImageProxy@f251aa8, width=864, height=480, y=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=430048 cap=430048], pixelStride=1, rowStride=896), u=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=215007 cap=215007], pixelStride=2, rowStride=896), v=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=215007 cap=215007], pixelStride=2, rowStride=896))

Hello, can you suggest what is the possible cause for this error? I noticed strange values width = 864 but rowStride = 896, may be this is the reason.

Sony Xperia XZ3 Black (H9436)

gordinmitya commented 4 years ago

@sellmair can you provide some info about these lines:

operator fun YuvImage.Factory.invoke(yuv: Yuv): YuvImage {
    // YuvImage.kt
    if (yuv.y.pixelStride != 1 || yuv.y.rowStride != yuv.width) { // <-- here
        throw UnsupportedImageFormatException(yuv)

// Yuv+defrag.kt
fun Yuv.defrag(): Yuv {
    val start = System.currentTimeMillis()

    require(y.pixelStride == 1)
    require(y.rowStride == width) // <--- and here

In documentation it's not stated that y.rowStride == width is always guaranteed. Why don't we just remove them and let defragPlanePadding do the job?

m-rm commented 4 years ago

Thanks for creating the issue, I have exactly the same problem using a Google Pixel 2.

com.quickbirdstudios.yuv2mat.UnsupportedImageFormatException: Yuv format is not supported: Yuv(resource=android.media.ImageReader$SurfaceImage@691a964, width=1440, height=1080, y=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=1589728 cap=1589728], pixelStride=1, rowStride=1472), u=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=794847 cap=794847], pixelStride=2, rowStride=1472), v=Plane(buffer=java.nio.DirectByteBuffer[pos=0 lim=794847 cap=794847], pixelStride=2, rowStride=1472))
        at com.quickbirdstudios.yuv2mat.YuvImageKt.invoke(YuvImage.kt:121)
        at com.quickbirdstudios.yuv2mat.YuvImageKt.invoke(YuvImage.kt:111)
        at com.quickbirdstudios.yuv2mat.Image_toMatKt.rgb(Image+toMat.kt:20)
        at com.quickbirdstudios.yuv2mat.Yuv$Companion.rgb(Yuv.kt:57)
gordinmitya commented 4 years ago

@m-rm I fixed it with commenting two lines I mentioned above

But that's not the best fix, because it will move all the pixels from NV21 format to YUV420. I'm going to create more efficient library – will post update here.

LiorA1 commented 4 years ago

you tried the camera2 API ?

gordinmitya commented 4 years ago

with camera api 1 we don't need that – there's ready to use byte[]

gordinmitya commented 4 years ago

@LiorA1 @m-rm made a correct implementation with unit tests, demo app, benchmarks https://github.com/gordinmitya/yuv2buf