Focus Areas
I am trying to implement a camera with a focus on a special area. So far I Have implemented a method from what I have seen in the tutorial
private void setFocusArea()
{
MeteringRectangle[] focusAreas = new MeteringRectangle[1];
Rect sensor_rect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
Rect focusArea = new Rect(
0,
0,
sensor_rect.width()-1,
(int)(sensor_rect.height()*0.5));
focusAreas[0] = new MeteringRectangle(focusArea,MeteringRectangle.METERING_WEIGHT_MAX);
if(mCameraCharacteristics!= null
&& mCameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF)>0)
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS,focusAreas);
// if(mCameraCharacteristics!= null
// && mCameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE)>0)
// mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,focusAreas);
}
And I am calling this function right before every mPreviewRequestBuilder.build()
So it is supposed to focus on the top 50% of the image, but it just doesn't.
Any ideas, feedback, or where should I look ?
Did you trigger af manually or set focus mode as CONTINUOUS_PICTURE?
I set focus mode to CONTINUOUS_PICTURE
Then maybe your focus area is too big, you can try another reasonable setting.
I have tried without setting any focus area and it does not work. It looks like it depends on the device, I have tested on a Motoroall Moto E, it is working, but it does NOT work on a Samsung S5.
Actually even the basic projet does not work on Samsung S5, I meant the continuous focus mode...
Hello @yaraki, did you have time to check this out? That's my priority now so we can even work together on that?
this working to me
`public void handleFocus(MotionEvent event) { int pointerId = event.getPointerId(0); int pointerIndex = event.findPointerIndex(pointerId); // Get the pointer's current position float x = event.getX(pointerIndex); float y = event.getY(pointerIndex);
Rect touchRect = new Rect(
(int) (x - 100),
(int) (y - 100),
(int) (x + 100),
(int) (y + 100) );
if (mCameraId == null) return;
CameraManager cm = (CameraManager)this.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics cc = null;
try {
cc = cm.getCameraCharacteristics(mCameraId);
} catch (CameraAccessException e) {
e.printStackTrace();
}
MeteringRectangle focusArea = new MeteringRectangle(touchRect,MeteringRectangle.METERING_WEIGHT_DONT_CARE);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
try {
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
} catch (CameraAccessException e){
// log
}
/* if (isMeteringAreaAESupported(cc)) {
*//*mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,
new MeteringRectangle[]{focusArea});*//*
}
if (isMeteringAreaAFSupported(cc)) {
*//*mPreviewRequestBuilder
.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusArea});
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_AUTO);*//*
}*/
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,
new MeteringRectangle[]{focusArea});
mPreviewRequestBuilder
.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusArea});
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
/* mManualFocusEngaged = true;*/
} catch (CameraAccessException e) {
// error handling
}
}`
@yudikarma, it is a bit late for me, I am not working for the same company anymore but I appreciate you took the time to reply, I am sure it will help other people.