点按以使用裁剪的GPUImage相机无法正常工作

时间:2014-12-12 19:41:32

标签: avfoundation gpuimage avcapturesession avcapturedevice

我有GPUImageStillCamera我正在使用构建相机然后裁剪为正方形

    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))];

我希望允许用户点按以调整对焦和曝光控制,同时我得到了水龙头,相机确实尝试调整焦距和曝光,它只能在大约30%的时间内正确调整。我想也许我需要发送未剪切相机的焦点(因为相对点会有所不同),但我得到了相同的体验。用户单击焦点和曝光调整但不会聚焦或在​​触摸点上设置适当的曝光。任何想法?

-(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];
}

1 个答案:

答案 0 :(得分:0)

(不是答案,但这对评论来说太长了,抱歉)

我有完全相同的问题。我已经尝试计算相对于我的裁剪预览图层的焦点,但焦点已关闭。然后我尝试使用captureDevicePointOfInterestForPoint。在你的情况下,我猜这将是(迅速):

let focusPoint = cameraHolder.layer.captureDevicePointOfInterestForPoint(translation)

我注意到在点击同一个地方两次后,它只关注正确的位置。此外,Apple文档建议曝光点和焦点是互斥的:

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

关于本文档中焦点应该是什么的更多解释:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html

如果你已经解决了,请告诉我:)。