【问题标题】:Reading iOS light sensor with ARKit使用 ARKit 读取 iOS 光传感器
【发布时间】:2020-10-16 03:36:38
【问题描述】:

有没有办法在完全不使用 AR 的情况下使用 ARKit 访问 iOS 设备的环境光传感器?

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

换句话说,我可以在不创建 AR 场景的情况下访问“ambientIntensity”的值吗?

【问题讨论】:

    标签: ios arkit light-sensor


    【解决方案1】:

    the docs for ARLightEstimate.ambientIntensity:

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

    换句话说,如果您想使用设备摄像头来估计当地的照明条件并且不使用 ARKit,那么您最好使用camera APIs。 (一方面,这些 API 在所有 iOS 11 设备和几个早期的 iO​​S 版本上都可用,而不需要 ARKit 的苛刻操作系统/硬件要求。)

    快速浏览您需要在那里做的事情:

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

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

    【讨论】:

      【解决方案2】:

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

      设置完成后,您可以调用currentFrame,它会为您提供ARFrame,其中包含lightEstimate 属性,其中包含ambientIntensity 估计值。

      【讨论】:

      • 谢谢,我设法让它工作(即使值有点奇怪)。我用self.arConfig = [ARWorldTrackingSessionConfiguration new]; self.arConfig.lightEstimationEnabled = YES; 并且设置了使用相机的权限。
      • 遗憾的是,它似乎无法与我需要的前置摄像头一起使用。
      【解决方案3】:

      是的,在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")
              }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多