I had starter project that used AVFoundation
to set up the Camera and it worked perfectly. Now I needed to convert the Camera mechanism into GPUImage
. I'm using the same focus and exposure method in both projects (which worked prefect at the AVFoundation
project) but at the GPUImage
project it doesn't focus properly and the always wrong.
Don't mind the applies filter it's the same over all of them
Sample : At the top right of the screen you can see the lamb. This is how it get focused + exposure.
Set up GPU :
stillCamera = GPUImageStillCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Front)
CorrectPosition = AVCaptureDevicePosition.Front
stillCamera!.outputImageOrientation = .Portrait;
stillCamera?.horizontallyMirrorFrontFacingCamera = true
filter = GPUImageFilter()
stillCamera?.addTarget(filter)
filter?.addTarget(self.view as! GPUImageView)
(self.view as! GPUImageView).fillMode = GPUImageFillModeType.init(2)
TouchBegan method:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
var tap : CGPoint!
if let touch = touches.first as UITouch! {
tap = touch.locationInView(self.view)
}
let device: AVCaptureDevice! = self.stillCamera?.inputCamera!
var error: NSError? = nil
do {
try device.lockForConfiguration()
if device.focusPointOfInterestSupported && device.isFocusModeSupported(AVCaptureFocusMode.AutoFocus){
device.focusMode = AVCaptureFocusMode.AutoFocus
device.focusPointOfInterest = tap
}
if device.exposurePointOfInterestSupported && device.isExposureModeSupported(AVCaptureExposureMode.AutoExpose){
device.exposurePointOfInterest = tap
device.exposureMode = AVCaptureExposureMode.AutoExpose
}
device.subjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange
device.unlockForConfiguration()
} catch let error1 as NSError {
error = error1
print(error)
} catch {
fatalError()
}
}
Any ideas?