Reputation: 592
I am trying to change focus by changing the point of interest as mentioned.
The function always returns a YES and when I use a getter to read the new focus point of interest, it has changed but isFocusAdjusting = NO
FYI:
focusMode: AVCaptureFocusModeContinuousAutoFocus
newFocusPointOfInterest: Normalized CGPoint
The focus seems to be locked at (0.5f, 0.5f) or basically AutoFocus
This code has worked on all the devices except iPhone 6 and iPhone 6+. Is there something that I'm doing wrong? Has any API call changed?
Please help
- (BOOL)changeDeviceFocusPointOfInterest:(CGPoint)newFocusPointOfInterest
focusMode:(AVCaptureFocusMode)focusMode
{
NSError *error;
BOOL ret = NO;
if([device lockForConfiguration:&error] )
{
if ([device isFocusModeSupported:focusMode] && [device isFocusPointOfInterestSupported])
{
[device setFocusPointOfInterest:newFocusPointOfInterest];
[device setFocusMode:focusMode];
ret = YES;
}
else
{
NSLog(@"focus point setting not supported:{%f,%f}", newFocusPointOfInterest.x, newFocusPointOfInterest.y);
ret = NO;
}
[device unlockForConfiguration];
}
else
{
NSLog(@"cant lock hardware settings for changing focus point:{%f,%f}", newFocusPointOfInterest.x, newFocusPointOfInterest.y);
ret = NO;
}
return ret;
}
**EDIT : Additional observations : **
I have checked the sample apps provided by Apple AVCam and AVCamManual - Tap to focus works on AVCam but not AVCamManual same device I have tried removing code related to the manual control in the sample workspace but it hasn't yielded any results.
Key Value observations show that there is NO change in lensPosition or focusAdjusting properties
I have found only one forum post on this problem but none of the work-arounds suggested seem to work https://devforums.apple.com/message/1073042#1073042
I have tried setting focus to a custom value, extreme and then setting mode to ContinousAuto with required focusPointOfInterest. This triggers focus change but does not focus at the required point of interest
Upvotes: 3
Views: 1966
Reputation: 592
This is not as much of an answer as it is a workaround.
From observation, when in AVCaptureFocusModeAutoFocus mode, the focus triggers a scan and focuses on the required point of interest and then then locks the focus (AVCaptureFocusModeLocked).
If you change mode to AVCaptureFocusModeContinuousAutoFocus, without changing the point of interest, the camera will perform a full frame focus and so the pointofinterest is rendered useless. (Determined from testing)
To imitate the continuous auto focus behaviour, I use AVCaptureDeviceSubjectAreaDidChangeNotification to monitor it manually by changing focus mode to AVCaptureFocusModeAutoFocus.
However, this is not as fast as AVCaptureFocusModeContinuousAutoFocus and I have observed a time gap of about 2-3 seconds between successive notifications.
If anyone has found a better solution, please share it here.
Note: Default camera of Apple also behaves in a similar manner. The difference lies in the fact that when the camera is moved in the default camera app of iPhone, the focus is set to AVCaptureFocusModeContinuousAutoFocus with (0.5, 0.5) as the focus point of interest.
Upvotes: 1