如何设置帧率与Android CameraX ImageAnalysis?



我想增加图像分析能够获得的FPS。我在主机上记录了这款游戏,它的最高帧数是10帧。我怎样才能把它调到30 FPS?

void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
final String TAG = "FPSCounter";
final long[] startTime = {System.currentTimeMillis()};
final int[] frameCount = {0};
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
long elapsedTime = System.currentTimeMillis() - startTime[0];
double fps = (double) frameCount[0] / (elapsedTime / 1000.0);
Log.d(TAG, "FPS: " + String.format("%.2f", fps));
frameCount[0] = 0;
startTime[0] = System.currentTimeMillis();
}
}, 1000, 1000);
Preview preview = new Preview.Builder().build();
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(this), image -> {
// This method will be called every time a new frame is available
// You can use the 'image' object to get the current frame
frameCount[0] = frameCount[0] + 1;
image.close();
});
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();
previewView = (PreviewView) findViewById(R.id.previewView);
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) this, cameraSelector, preview, imageAnalysis);
}

我读到在CameraX图像分析中设置FPS没有一致的方法,但我希望有人能够帮助我。谢谢你!

可能太晚了,但对于任何为此而挣扎的人来说,我记得这是可能通过Camera2Interop Extender实现的。可以这样设置:

val ext = Camera2Interop.Extender(imageAnalysisConfig)
ext.setCaptureRequestOption(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO)
ext.setCaptureRequestOption(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range<Int>(30, 30))

其中imageAnalysisConfig为:

val imageAnalysisConfig = ImageAnalysis.Builder()
.setTargetResolution(Size(PREVIEW_HEIGHT, PREVIEW_WIDTH))
.apply {
setImageQueueDepth(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
}

最新更新