摄像头像素旋转 [英] camera pixels rotated

查看:196
本文介绍了摄像头像素旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做一些图像处理从相机得到的像素。

I want to do some image processing to the pixels gotten from the camera.

的问题是,从相机中的像素旋转90度。

The problem is that the pixels from the camera are rotated 90 degrees.

即时得到的像素在previewFrame的方法内(byte []的数据,摄像头摄像头)

我试过 camera.setDisplayOrientation(90); ,并显示在正确的方向的视频,但我仍然收到了旋转像素的文档中所述:

I tried camera.setDisplayOrientation(90); and it displays the video in the correct orientation but I am still receiving the rotated pixels as stated in the documentation:

这不会影响字节数组的传递顺序   Android.Hardware.Camera.I previewCallback.On previewFrame(字节[],   Android.Hardware.Camera),JPEG图片或录制的视频。

This does not affect the order of byte array passed in Android.Hardware.Camera.IPreviewCallback.OnPreviewFrame(Byte[], Android.Hardware.Camera), JPEG pictures, or recorded videos.

我也试过:

parameters.setRotation(90);
camera.setParameters(parameters);

但没有奏效。

but that did not work.

我使用的是Android 2.2的

I'm using android 2.2

首图显示了SurfaceView使用 camera.setDisplayOrientation(90)时;

Top image shows the SurfaceView when using camera.setDisplayOrientation(90);

第二图像得到里面在previewFrame(byte []的数据,摄像头摄像头)数据阵列。正如你所看到的数据阵列自带旋转。

The second image is gotten inside onPreviewFrame(byte[] data, Camera camera) from the data array. As you can see the data array comes rotated.

推荐答案

如果您收到一个YUV420字节数组,然后下面的方法可以通过90度旋转这一点。

If you are receiving a YUV420 byte array then the following method can rotate this by 90 degree.

private byte[] rotateYUV420Degree90(byte[] data, int imageWidth, int imageHeight) 
{
    byte [] yuv = new byte[imageWidth*imageHeight*3/2];
    // Rotate the Y luma
    int i = 0;
    for(int x = 0;x < imageWidth;x++)
    {
        for(int y = imageHeight-1;y >= 0;y--)                               
        {
            yuv[i] = data[y*imageWidth+x];
            i++;
        }
    }
    // Rotate the U and V color components 
    i = imageWidth*imageHeight*3/2-1;
    for(int x = imageWidth-1;x > 0;x=x-2)
    {
        for(int y = 0;y < imageHeight/2;y++)                                
        {
            yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+x];
            i--;
            yuv[i] = data[(imageWidth*imageHeight)+(y*imageWidth)+(x-1)];
            i--;
        }
    }
    return yuv;
}

(注意,这可能仅工作,如果该宽度和高度是一个因子4)

(Note that this might only work if the width and height is a factor of 4)

这篇关于摄像头像素旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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