Nexus 9 Camera2 API-YUV_420_888与getOutputSizes() [英] Nexus 9 Camera2 API - YUV_420_888 vs. getOutputSizes()

查看:298
本文介绍了Nexus 9 Camera2 API-YUV_420_888与getOutputSizes()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Nexus 9上以YUV_420_888格式实现Camera2 API.我检查了输出尺寸,并希望使用最大尺寸(8MP,3280 x 2460)进行保存.但是,它只是显示为静态线,类似于没有信号的老式电视机.我想坚持使用YUV_420_888,因为我的最终目标是保存灰度数据(Y分量).

I'm implementing the Camera2 API with the YUV_420_888 format on a Nexus 9. I checked the output sizes and wanted to use the largest (8MP, 3280 x 2460) size to save. However, it just appears as static lines, similar to how old TV's looked without a signal. I would like to stick with YUV_420_888 since my end goal is to save grayscale data (Y component).

我本来以为这是相机带宽问题,但是在某些小尺寸(320 x 240)上也发生了同样的事情.即使增加帧持续时间并减小预览大小以节省带宽,所有问题都不会消失.其他一些DID尺寸也可以使用(2048 x 1536、1280 x 720),但我并未全部检查.

I originally thought it was a camera bandwidth issue, but the same thing happened at some of the small sizes (320 x 240). None of the problems went away even when I increased frame duration and decreased the size of the preview to save on bandwidth. Some of the other sizes DID work (2048 x 1536, 1280 x 720) but I did not check all of them.

我开始认为getOutputSizes()不一定准确.除RAW_SENSOR(JPEG,YUV_420_888,YV12)外,其他所有格式的结果都相同.有没有人遇到过这个问题或已确定解决方案?

I'm starting to think getOutputSizes() may not necessarily be accurate. It gave me the same results for all other formats except RAW_SENSOR (JPEG, YUV_420_888, YV12). Has anyone encountered this or determined a solution?

推荐答案

找出了问题所在.我没有考虑返回像素的rowStride.所以我必须运行一个for循环来提取未填充的数据,然后再保存它:

Figured out the issue. I was not taking into account the rowStride of the returned pixels. So I had to run a for-loop to extract the non-padded data before saving it:

myRowStride = mImage.getPlanes()[0].getRowStride();
int iSkippedBytes = 0;
for (int i = 0; i < mStillSize.getWidth() * mStillSize.getHeight(); i++){
    if (i % mStillSize.getWidth() == 0 && i != 0)
          iSkippedBytes = iSkippedBytes + (myRowStride - mStillSize.getWidth());
    imageBytes[i] = bytes[i + iSkippedBytes];
 }

这篇关于Nexus 9 Camera2 API-YUV_420_888与getOutputSizes()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆