Ios 在自定义相机层上的AVFoundation中自动对焦和自动曝光
为AVFoundation自定义层相机创建精确的自动对焦和曝光的最佳方法是什么?。例如,当前我的相机预览层是方形的,我希望将相机对焦和曝光指定到该帧边界。我需要这在Swift 2如果可能的话,如果没有请写下你的答案,我将能够转换它自己 当前自动对焦和曝光:但正如您所见,这将在对焦时评估整个视图Ios 在自定义相机层上的AVFoundation中自动对焦和自动曝光,ios,swift,camera,avfoundation,swift2,Ios,Swift,Camera,Avfoundation,Swift2,为AVFoundation自定义层相机创建精确的自动对焦和曝光的最佳方法是什么?。例如,当前我的相机预览层是方形的,我希望将相机对焦和曝光指定到该帧边界。我需要这在Swift 2如果可能的话,如果没有请写下你的答案,我将能够转换它自己 当前自动对焦和曝光:但正如您所见,这将在对焦时评估整个视图 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { //Get Touch P
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//Get Touch Point
let Point = touches.first!.locationInView(self.capture)
//Assign Auto Focus and Auto Exposour
if let device = currentCameraInput {
do {
try! device.lockForConfiguration()
if device.focusPointOfInterestSupported{
//Add Focus on Point
device.focusPointOfInterest = Point
device.focusMode = AVCaptureFocusMode.AutoFocus
}
if device.exposurePointOfInterestSupported{
//Add Exposure on Point
device.exposurePointOfInterest = Point
device.exposureMode = AVCaptureExposureMode.AutoExpose
}
device.unlockForConfiguration()
}
}
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
//获得接触点
让Point=touch.first!.locationInView(self.capture)
//指定自动对焦和自动曝光
如果let设备=currentCameraInput{
做{
试试!device.lockForConfiguration()
如果支持device.focusPointOfInterest{
//把重点放在重点上
device.focusPointOfInterest=点
device.focusMode=AVCaptureFocusMode.AutoFocus
}
如果支持device.exposurePointOfInterest{
//增加曝光点
device.exposurePointOfInterest=点
device.exposureMode=AVCaptureExposureMode.AutoExpose
}
device.unlockForConfiguration()
}
}
}
相机层:1:1比例的任何东西都应被视为焦点和曝光点,超出此范围的任何东西都不会被视为相机焦点的触摸事件
将根据AVCaptureVideoPreviewLayer的设置为您提供设备关注点。请参阅。多亏了JLW,以下是您在Swift 2中的操作方法。首先,我们需要设置点击手势,您可以通过编程或故事板来实现
//Add UITap Gesture Capture Frame for Focus and Exposure
let captureTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "AutoFocusGesture:")
captureTapGesture.numberOfTapsRequired = 1
captureTapGesture.numberOfTouchesRequired = 1
self.captureFrame.addGestureRecognizer(captureTapGesture)
在capturetapership
中基于选择器创建函数
/*=========================================
* FOCUS & EXPOSOUR
==========================================*/
var animateActivity: Bool!
internal func AutoFocusGesture(RecognizeGesture: UITapGestureRecognizer){
let touchPoint: CGPoint = RecognizeGesture.locationInView(self.captureFrame)
//GET PREVIEW LAYER POINT
let convertedPoint = self.previewLayer.captureDevicePointOfInterestForPoint(touchPoint)
//Assign Auto Focus and Auto Exposour
if let device = currentCameraInput {
do {
try! device.lockForConfiguration()
if device.focusPointOfInterestSupported{
//Add Focus on Point
device.focusPointOfInterest = convertedPoint
device.focusMode = AVCaptureFocusMode.AutoFocus
}
if device.exposurePointOfInterestSupported{
//Add Exposure on Point
device.exposurePointOfInterest = convertedPoint
device.exposureMode = AVCaptureExposureMode.AutoExpose
}
device.unlockForConfiguration()
}
}
}
此外,如果您想使用动画指示器,请在触摸事件时使用接触点,并将其指定给动画层
//Assign Indicator Position
touchIndicatorOutside.frame.origin.x = touchPoint.x - 10
touchIndicatorOutside.frame.origin.y = touchPoint.y - 10
您正在使用AVCaptureVideoPreviewLayer吗?如果是:
public func captureDevicePointOfInterestForPoint(pointInLayer:CGPoint)->CGPoint
@jlw是的,我正在使用AVCaptureVideoPreviewLayer
,但我没有看到该函数。:/@哇,我怎么会错过呢?请纠正你的回答,我会接受的。谢谢
//Assign Indicator Position
touchIndicatorOutside.frame.origin.x = touchPoint.x - 10
touchIndicatorOutside.frame.origin.y = touchPoint.y - 10