Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to understand padding issues #3

Closed
acoutts opened this issue Jan 13, 2023 · 3 comments
Closed

Trying to understand padding issues #3

acoutts opened this issue Jan 13, 2023 · 3 comments

Comments

@acoutts
Copy link

acoutts commented Jan 13, 2023

Hi. On some android devices I’ve observed that there is some padding added. The row stride is > the image width on all 3 planes (YUV420).

Through trial and error I found I only need to trim the padding from the luma channel but not the chroma channels. Coincidentally the pixel stride is 1 on the luma channel and 2 on the chroma channels.

I’m trying to understand why the padding sometimes exists and why it can only be trimmed when pixel stride is 1.

In my example I observed the following on some devices when streaming YUV420 from camera2:
Image width: 1280
Image height: 720
Y pixel stride: 1
Y row stride: 1536
U pixel stride: 2
U row stride: 1536
V pixel stride: 2
V row stride: 1536

@gordinmitya
Copy link
Owner

Hello @acoutts, just added a test case with your numbers and I looks like code handles them correctly.

Could you check that's is different on your device vs test case above? And also what is exact issues you faced (crash, wrong picture, smth else)?

@acoutts
Copy link
Author

acoutts commented Jan 14, 2023

Sorry I should clarify the code works great! I just want to better understand why the row stride can sometimes differ and why padding may or may not be present.

@gordinmitya
Copy link
Owner

usually stride may appear when we take crop of the image, so must be 1280x720 is not "native" resolution for camera on your device, so it captures more pixels and just returns you central crop.
in this case rowStride includes "padding" to skip these extra pixels and get to the next row of crop:

IMG_34CA8A7FB8A3-1
1024 took just for example, we can't derive actual height from these parameters

so in case if native resolution of camera matches with requested resolution – there won't be any padding. Hope this helps you understand. For more examples you can google how Mat cropping is implemented in OpenCV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants