使用 ARKit 读取 iOS 光传感器



有没有办法使用ARKit访问iOS设备的环境光传感器,而无需使用AR?

https://developer.apple.com/documentation/arkit/arlightestimate/2878308-ambientintensity

换句话说,我可以在不创建AR场景的情况下访问"环境强度"的值吗?

请参阅文档以了解ARLightEstimate.ambientIntensity

此值基于相机设备的内部曝光补偿

换句话说,如果要使用设备相机来估计局部照明条件,并且不使用 ARKit,则最好使用相机 API。(首先,这些 API 在所有 iOS 11 设备和几个早期的 iOS 版本上都可用,而不需要 ARKit 的陡峭操作系统/硬件要求。

快速浏览您需要在那里执行的操作:

  1. 设置AVCaptureSession并选择相机AVCaptureDevice你想要的。您可能需要也可能不需要连接视频/照片捕获输出(在您的情况下,该输出大多未使用(。
  2. 开始运行捕获会话。
  3. 使用 KVO 监控AVCaptureDevice上的曝光、温度和/或白平衡相关属性。

您可以在Apple的AVCamManual示例代码中找到涵盖所有这些(以及更多内容,因此您需要提取与您相关的部分(的(较旧的,ObjC(代码。

你不需要ARSCNView但你需要有一个正在运行的ARSessionhttps://developer.apple.com/documentation/arkit/arsession

完成该设置后,您可以调用currentFrame,这将为您提供一个ARFrame,该具有包含ambientIntensity估计值的lightEstimate属性。

是的,在 captureOutput 函数中,在适应协议时要覆盖 AVCaptureVideoDataOutputSampleBufferDelegate

override func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
//Retrieving EXIF data of camara frame buffer
let rawMetadata = CMCopyDictionaryOfAttachments(allocator: nil, target: sampleBuffer, attachmentMode: kCMAttachmentMode_ShouldPropagate)
let metadata = CFDictionaryCreateMutableCopy(nil, 0, rawMetadata) as NSMutableDictionary
let exifData = metadata.value(forKey: "{Exif}") as? NSMutableDictionary

if let light = exifData?[kCGImagePropertyExifBrightnessValue] as? NSNumber {
print("Light (light.floatValue)")
} else {
print("problem with light")
}
}

最新更新