我想增加图像分析能够得到的FPS。我在控制台上登录了它,它的最高速度约为10 FPS。如何让它达到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没有一致的方法,但我希望有人能够帮助我。谢谢你!
1条答案
按热度按时间gk7wooem1#
可能太晚了,但对于任何人挣扎与此,我记得这是可能的通过Camera2Interop扩展器。可以这样设置:
其中
imageAnalysisConfig
是: