Is there a way to access the ambient light sensor of an iOS device, using the ARKit, without using the AR at all?
https://developer.apple.com/documentation/arkit/arlightestimate/2878308-ambientintensity
In other words, can I access the value of "ambientIntensity" without creating an AR scene.
See the docs for ARLightEstimate.ambientIntensity
:
This value is based on the internal exposure compensation of the camera device
In other words, if you want to use the device camera to estimate local lighting conditions and aren't otherwise using ARKit, you might be better off using the camera APIs . (For one thing, those APIs are available on all iOS 11 devices and several earlier iOS versions, rather than needing the steep OS/hardware requirements of ARKit.)
A quick tour of what you'll need to do there:
AVCaptureSession
and choose the camera AVCaptureDevice
that you want. You may or may not need to wire up a video/photo capture output (which in your case will be mostly unused).AVCaptureDevice
.You can find (older, ObjC) code covering all this (and a lot more, so you'll need to extract the parts that are relevant to you) in Apple's AVCamManual sample code .
You don't need an ARSCNView
but you do need to have a running ARSession
https://developer.apple.com/documentation/arkit/arsession
Once you have that set up you can call currentFrame
which will give you an ARFrame
which has a lightEstimate
property which contains the ambientIntensity
estimate.
Yes, in the captureOutput function to override when adapting the Protocol 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")
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.