Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emulating the camera apps 'tap to focus'

I am trying hard to emulate the basic functionality of the built in camera app. Thus far I have become stuck on the 'tap to focus' feature.

I have a UIView from which I am collecting UITouch events when a single finger is tapped on the UIView. This following method is called but the camera focus & the exposure are unchanged.

-(void)handleFocus:(UITouch*)touch
{ 
     if( [camera lockForConfiguration:nil] )
     {     
          CGPoint location = [touch locationInView:cameraView];

          if( [camera isFocusPointOfInterestSupported] )
               camera.focusPointOfInterest = location;

          if( [camera isExposurePointOfInterestSupported] )
               camera.exposurePointOfInterest = location;


          [camera unlockForConfiguration];
          [cameraView animFocus:location];
     }
}

'camera' is my AVCaptureDevice & it is non-nil. Can someone perhaps tell me where I am going wrong?

Clues & boos all welcome.

M.

like image 227
Martin Cowie Avatar asked Jul 27 '10 16:07

Martin Cowie


1 Answers

This snippet might help you...There is a CamDemo provided by apple floating around which allows you to focus, change exposure while tapping, set flash, swap cameras and more, it emulates the camera app pretty well, not sure if youll be able to find it since it was part of wwdc, but if u leave some email address in the comments i can email you the sample code...

- (void) focusAtPoint:(CGPoint)point

{

    AVCaptureDevice *device = [[self videoInput] device];

    if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {

        NSError *error;

        if ([device lockForConfiguration:&error]) {

            [device setFocusPointOfInterest:point];

            [device setFocusMode:AVCaptureFocusModeAutoFocus];

            [device unlockForConfiguration];

        } else {

            id delegate = [self delegate];

            if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {

                [delegate acquiringDeviceLockFailedWithError:error];

            }

        }        

    }

}
like image 155
Daniel Avatar answered Oct 06 '22 00:10

Daniel