Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tap to adjust focus / exposure in CameraX

I would like to implement the standard UX of tapping a point on the preview to adjust the auto-focus and auto-exposure points to the place where they tapped. I found the Preview.focus() function, however it says that it needs dimensions in the "sensor coordinate frame", which I'm assuming is not the same as the TextureView's TouchEvent pixel coordinates.

How do I convert from the TextureView preview's touch coordinates to the "sensor coordinate frame" expected by Preview.focus()?

It would be great if this example was part of the sample code, as it seems like a pretty common use case that nearly everyone will expect.

like image 387
phreakhead Avatar asked May 30 '19 18:05

phreakhead


1 Answers

TextureView's coordinates are not the same as sensor coordinates. Please refer to the sample codes here (Please note that the "CameraView" is not public in maven repository yet. So we do not encourage you use it now). We understand these are a lot of work so CameraX team is also developing a more developer-friendly version of focus/metering API.

The basic flow is as below: (1) get x, y from a view touch event. (2) Calculate the relative camera orientation using device orientation and camera2 CameraCharacteristics.SENSOR_ORIENTATION. The value represents the clockwise angle through which the sensor image needs to be rotated to be upright in current device orientation.
(3) swap x, y for 90 / 270 degree , and reverse the x, y properly by the orientation. reverse the x for mirroring (front camera) (4) transform to the sensor coordinates using CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE), view width/height .

note: for the camera id, for now you can get find first camera_id in mCameraManager.getCameraIdList() with correct lens facing. however the algorithm could be changed.

like image 108
Scott Nien Avatar answered Sep 30 '22 08:09

Scott Nien