How to increase frame rate with Android CameraX ImageAnalysis?

后端 未结 3 478

I\'m investigating the new CameraX API, in relation to how viable it might be to switch over from our current Camera2 system.

In our Camera2 system, we use an OpenG

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 15:28

    Unfortunately, Iain Stanford answer did not help me. My app just crash after adding any of these lines to Camera2Config.Extender:

    .setCaptureRequestOption(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_OFF)
    .setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF)
    .setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF)
    .setCaptureRequestOption(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_OFF)
    

    I got this error:

    IllegalArgumentException: Unsupported session configuration combination
    

    But, luckily, I found a way to get 60 FPS another way on Pixel 2 XL. Took some code from here. Unfortunately, it works only if I draw Preview as TextureView. If I use don't use AutoFitPreviewBuilder function and don't draw Preview as TextureView, all Extender settings will be ignored.

    So, my code:

    imageAnalysis = ImageAnalysis(createImageAnalysisConfig())
    
    val previewConfig  = createImagePreviewConfig()
    Camera2Config.Extender(previewConfig)
        .setCaptureRequestOption(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range(60, 60))             
        .setCaptureRequestOption(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 1)
    
    val preview = AutoFitPreviewBuilder.build(previewConfig.build(), viewFinder)
    
    CameraX.bindToLifecycle(lifecycleOwner, imageAnalysis, preview)
    preview.enableTorch(true)
    

    Where AutoFitPreviewBuilder is function from android repo examples and viewFinder is TextureView, imageAnalysis is ImageAnalysisConfig.Builder().build and createImagePreviewConfig() returns PreviewConfig.Builder(). Btw, do not forget to set max resolution for camera in ImageAnalysisConfig & PreviewConfig:

    .setMaxResolution(Size(800, 800))
    

    Hope, it will help you.

提交回复
热议问题