5

I want to use ImageAnalysis with CameraX, but adjust some Camera settings such as auto-focus or auto-white balance, exposure and frame duration.

Here's an example of the settings I need and how I set them with Camera2:

    captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_OFF)
    captureRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF)
    captureRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, FRAME_DURATION_NS)
    captureRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, EXPOSURE_TIME_LIMIT_NS)

How can I "translate" this to CameraX?

Sharp
  • 1,335
  • 1
  • 12
  • 27

1 Answers1

12

There is Camera2InterOp for customizing CaptureRequest parameters. Example:

fun buildImageAnalysis() : ImageAnalysis {
    val builder = ImageAnalysis.Builder()
    val camera2InterOp = Camera2Interop.Extender(builder)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_OFF)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF)
    camera2InterOp.setCaptureRequestOption(CaptureRequest.SENSOR_FRAME_DURATION, FRAME_DURATION_NS);
    camera2InterOp.setCaptureRequestOption(CaptureRequest.SENSOR_EXPOSURE_TIME, EXPOSURE_TIME_LIMIT_NS)
    return builder.build()
}
Xi 张熹
  • 10,492
  • 18
  • 58
  • 86
  • This works as a standalone solution, but when I try to also add an analyzer like this - `buildImageAnalysis().setAnalyzer(analysisExecutor, ImageAnalysis.Analyzer { })` - I get `java.lang.IllegalArgumentException: Unsupported session configuration combination`. Any ideas why does it not work with the CameraX analyzer? – Sharp Mar 09 '20 at 10:04
  • Looks like they fixed it with the newest beta versions and now proper interop is allowed, although they do not guarantee it works. I'm very disappointed with CameraX, but oh well, at least it works. – Sharp Jun 03 '20 at 14:14
  • Did you implement selecting manual AWB using `CameraX` or `Camera2CameraControl.from(camera!!.cameraControl).captureRequestOptions` @Sharp – Ramana Reddy Jun 28 '21 at 13:43
  • @RamanaReddy CameraX through Camera2Interop as shown above. – Sharp Jun 28 '21 at 15:38