Chase S
Chase S

Reputation: 468

Tap To Focus Not Working Properly with Cropped GPUImage Camera

I have a GPUImageStillCamera I am using to build a camera that I then crop to a square

    stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
stillCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

//Creating a square crop filter
cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.f, (720.0f/1280.0f)/2.0f, 1.f, (720.0f/1280.0f))];

I want to allow the user to tap to adjust focus and exposure control and whileI get the tap and the camera does try to adjust the focus and exposure it only gets it right about 30% of the time. I thought maybe I needed to send a focus point of the uncropped camera (since the relative points would differ) but I get the same experience. A user clicks the focus and exposure adjust but it does not focus or set proper exposure on the touch point. Any Ideas?

-(void)imageTouch:(UITapGestureRecognizer *)recognizer{

//Focus point relative to the square
//CGPoint translation = [recognizer locationInView:cameraImagePreview];
//CGPoint focusPoint = CGPointMake(translation.x/cameraHolder.frame.size.width, translation.y/cameraHolder.frame.size.height);

//Focus point relative to the uncropped camera
CGPoint translation = [recognizer locationInView:fullCameraFocusPoint];
CGPoint focusPoint = CGPointMake(translation.x/fullCameraFocusPoint.frame.size.width, translation.y/fullCameraFocusPoint.frame.size.height);


//Set the focus point of the camera
if (stillCamera.inputCamera.isFocusPointOfInterestSupported && [stillCamera.inputCamera isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {

    [stillCamera.inputCamera lockForConfiguration:nil];
    stillCamera.inputCamera.focusPointOfInterest = focusPoint;
    stillCamera.inputCamera.focusMode = AVCaptureFocusModeAutoFocus;

    if (stillCamera.inputCamera.exposurePointOfInterestSupported && [stillCamera.inputCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]) {
        stillCamera.inputCamera.exposurePointOfInterest = focusPoint;
        stillCamera.inputCamera.exposureMode = AVCaptureExposureModeAutoExpose;
    }

    [stillCamera.inputCamera unlockForConfiguration];
}

Upvotes: 1

Views: 506

Answers (1)

muxcmux
muxcmux

Reputation: 237

(Not an answer, but this is too long for a comment, sorry)

I have the exact same problem. I have tried calculating the focus point relative to my cropped preview layer but the focus was off. Then I tried using captureDevicePointOfInterestForPoint. In your case I guess that would be (swift):

let focusPoint = cameraHolder.layer.captureDevicePointOfInterestForPoint(translation)

I've noticed it only focuses on the correct position after tapping on the same place twice. Also, Apple docs suggest that exposure point and focus point are mutually exclusive:

Note: Focus point of interest and exposure point of interest are mutually exclusive, as are focus mode and exposure mode.

There's more explanation on what exactly the focus point should be in this document: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html

Let me know if you have solved it :)

Upvotes: 0

Related Questions