Ios autofucus or continuous focus

Hi, I hav an app that works fine but I need to add autofocus, or at least refocus. I dont mind if the user has to tap to trigger focus, or if it is constant autofocus.

I saw a few posts, the only recent ones I saw are:


I did not have any luck makign this work with an iphone 6.

Has anyone out there got a solution?

One road I started down is to try and make it myself with objective C, how could I get access to the captureInput.device (the avfoundation grabber) from my ofApp.cpp to apply focus?

When I made artgram ( I modified few OF classes to accept focus commands.

First of all, you can both set the focus to a specific distance (number between 0.0 and 1.0 where 0.0 is the closest distance and 1.0 is the furthest), or you can specify a set of XY coordinates for a location in your picture to set the focus point.

I added the following methods to

-(void)setAutofocusWithPointOfInterest:(CGPoint) p{

[captureInput.device setFocusMode:AVCaptureFocusModeAutoFocus];
[captureInput.device lockForConfiguration:nil];

[captureInput.device setFocusPointOfInterest:p];
[captureInput.device unlockForConfiguration];


 [captureInput.device lockForConfiguration:nil];
 [captureInput.device setFocusModeLockedWithLensPosition:newFocus completionHandler:^(CMTime syncTime) {     }];
 [captureInput.device unlockForConfiguration];


And I modiefied ofxiOSVideoGrabber to have the following methods:

void ofxiOSVideoGrabber::setAutofocusWithPointOfInterest(int x, int y){



void ofxiOSVideoGrabber::setFocusManuallyTo(float newFocus){



So from OF you can just call:

videoFeed.getGrabber<ofxiOSVideoGrabber>()->setAutofocusWithPointOfInterest(0, 0);



1 Like

Hey thanks that seems to work pretty well. In case anyone else sees this I had to wrap the objective C functions in AVFoundationVideoGrabber with C++ functions.

One thing that setFocusPointOfInterest needs a float between 0 and 1 for the position.

1 Like

hello! after doing changes that pierdr suggests (and adding definitions in h file, i got an error:

Undefined symbols for architecture arm64:
“ofxiOSVideoGrabber::setAutofocusWithPointOfInterest(int, int)”, referenced from:
ofApp::touchDown(ofTouchEventArgs&) in ofApp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

what can i do?
im very new to cpp and of, thank u for detailed answer