相机像素旋转
我想对从相机获得的像素进行一些图像处理。
问题在于相机的像素旋转了 90 度。
我在方法 onPreviewFrame(byte[] data, Camera camera)
中获取像素,
我尝试了 camera.setDisplayOrientation(90);
并且它以正确的方向显示视频,但是我仍然收到文档中所述的旋转像素:
这不会影响传入的字节数组的顺序 Android.Hardware.Camera.IPreviewCallback.OnPreviewFrame(Byte[], Android.Hardware.Camera)、JPEG 图片或录制的视频。
我也尝试过:
parameters.setRotation(90);
camera.setParameters(parameters);
但是没有用。
我正在使用 android 2.2
使用 camera.setDisplayOrientation(90) 时顶部图像显示 SurfaceView ;
第二张图像是从 data
数组中的 onPreviewFrame(byte[] data, Camera camera)
中获取的。正如您所看到的,data
数组已旋转。
I want to do some image processing to the pixels gotten from the camera.
The problem is that the pixels from the camera are rotated 90 degrees.
Im getting the pixels inside the method onPreviewFrame(byte[] data, Camera camera)
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:
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.
I also tried:
parameters.setRotation(90);
camera.setParameters(parameters);
but that did not work.
I'm using android 2.2
Top image shows the SurfaceView when using camera.setDisplayOrientation(90);
The second image is gotten inside onPreviewFrame(byte[] data, Camera camera)
from the data
array. As you can see the data
array comes rotated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然我来得有点晚了,但这里有一个我写的方法,其他人可能会发现它对于旋转 YUV420sp (NV21) 图像很有用。我在 SO 上看到的其他方法似乎都没有真正做到这一点。
While I'm a bit late to the party, here's a method I wrote that others might find useful to rotate a YUV420sp (NV21) image. None of the other methods I saw on SO seemed to actually do it.
也许您可以在横向框架上执行图像处理,并且仅在显示它时担心旋转(您已经完成了)。如果没有,您需要以老式方式旋转框架。我在某处找到了一些代码(稍加修改)可能会有所帮助:
这很容易,因为 createBitmap 方法支持矩阵变换:
http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap,int,int,int,int,android.graphics.Matrix,布尔)
Maybe you can perform your image processing on the sideways frame, and only worry about rotation when you display it (which you have already done). If not, you need to rotate the frame the old fashioned way. I found some code somewhere (with a little modification) that might help:
This is easy because the createBitmap method supports a matrix transform:
http://developer.android.com/reference/android/graphics/Bitmap.html#createBitmap(android.graphics.Bitmap, int, int, int, int, android.graphics.Matrix, boolean)
如果您收到 YUV420 字节数组,则以下方法可以将其旋转 90 度。
(请注意,只有宽度和高度是 4 倍时,这才可能有效)
If you are receiving a YUV420 byte array then the following method can rotate this by 90 degree.
(Note that this might only work if the width and height is a factor of 4)
您可以按如下方式旋转原始数据:
其中“宽度”和“高度”是预览图像的预设尺寸,使用:
然后您可以相应地使用旋转数据。
我只用过这种方法来扫描二维码,看起来效果很好。不确定它会如何影响其他应用程序。
You can rotate the raw data as follows:
Where 'width' and 'height' are the pre-set sizes for your preview image using:
You can then use your rotated data accordingly.
I've only used this method for QR Code scanning and it appears to work perfectly. Not sure how it might effect other applications.