自动对焦和自动曝光在自定义相机图层上的AVFoundation [英] Auto Focus and Auto Exposure in AVFoundation on Custom Camera Layer
问题描述
为 AVFoundation 自定义图层相机创建准确自动聚焦和曝光的最佳方法是什么?例如,当前我的相机预览图层是正方形,像相机焦点和曝光以指定到该帧限制。
当前自动对焦和曝光:
strong>但是正如你可以看到,这将评估整个视图时,聚焦。 override func touchesBegan(touches:Set< UITouch> withEvent event:UIEvent?){
// Get Touch Point
let Point = touches.first!.locationInView(self.capture)
//分配自动聚焦和自动曝光
如果let device = currentCameraInput {
do {
尝试! device.lockForConfiguration()
if device.focusPointOfInterestSupported {
//添加焦点
device.focusPointOfInterest = Point
device.focusMode = AVCaptureFocusMode.AutoFocus
}
如果device.exposurePointOfInterestSupported {
//在点上添加曝光
device.exposurePointOfInterest = Point
device.exposureMode = AVCaptureExposureMode.AutoExpose
}
device.unlockForConfiguration()
}
}
}
相机图层:1:1比例中的任何内容都应被视为焦点和曝光点,任何超出此范围的内容都不会被视为相机焦点的触摸事件。
code> public func captureDevicePointOfInterestForPoint(pointInLayer:CGPoint) - > CGPoint
将根据AVCaptureVideoPreviewLayer的设置指定设备的焦点。请参见文档。 / p>
What is the best way to create an accurate Auto Focus and Exposure for AVFoundation custom layer camera?, for example, currently my camera preview layer is square, I would like the camera focus and exposure to be specify to that frame bound. I need this in Swift 2 if possible, if not please write your answer I would be able to convert it myself.
Current Auto Focus and Exposure: But as you can see this will evaluate the entire view when focusing.
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()
}
}
}
Camera Layer: Anything in the 1:1 ratio should be considered as focus and exposure point, and anything outside this bound would not even be considered as a touch event for camera focus.
public func captureDevicePointOfInterestForPoint(pointInLayer: CGPoint) -> CGPoint
will give you the point for the device to focus on based on the settings of your AVCaptureVideoPreviewLayer. See the docs.
这篇关于自动对焦和自动曝光在自定义相机图层上的AVFoundation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!