大家好,前几天我遇到了相机预览回调的问题,我想扫描每一帧
在添加的 PreviewCallback 中,我有设备 (motorola g) 可以提供 30 fps。下面是
预览回调中的代码。
private PreviewCallback previewCallback = new PreviewCallback() {
/**
* {@inheritDoc}
*/
@Override
public void onPreviewFrame(byte[] data, Camera cam)
{
if (data == null) throw new NullPointerException();
Camera.Size size = cam.getParameters().getPreviewSize();
if (size == null) throw new NullPointerException();
int width = size.width;
int height = size.height;
// maximum value of the range of sum (Red) values in each frame 1/10 part of every 5th
// pixel red value sum ( if all pixels consider the red(255) then max value of sum of r)
final double analysisFrameSize = (((width * height)/100)/5f)* 255;
ImageProcessing.setMaxPixelPerFrame(analysisFrameSize);
ImageProcessModel model = ImageProcessing.decodeYUV420SPtoRedAvg(data.clone(), width, height);
List<Integer> furtherAnaylisList = model.getmFurtherAnalysisList();
final int frameSize = (((width * height)/100)/5);
int redAvg = (furtherAnaylisList.get(0) / frameSize);
int green = (furtherAnaylisList.get(1) / frameSize);
int blue = (furtherAnaylisList.get(2) / frameSize);
Log.println(TAG,String.format("AvgRed:%2d,AvgGree:%2d,AvgBlue:%2d",redAvg,green,blue));
}
};
程序是否会降低预览回调中的帧速率,因为在编写代码后它会降低 fps 30 fps 到 22 fps,我对 22 fps 没有问题,但它不是恒定的。
我可以将相机设置为 22 或 30 fps 常数吗?
提前谢谢你。
最佳答案
Can I set the camera for give me the 22 or 30 fps constant.
不,但是您可以将图像处理工作转移到后台线程,这样就不会降低相机的速度。
关于Android Camera Preview 回调变慢我们需要恒定的 fps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26340558/