I'm trying to use the front-facing camera as a brightness sensor (there is no public API for the separate brightness sensor that's used to adjust the screen brightness, apparently).
I've managed to set up a video capture session and grab frames from the video, using AVCaptureVideoOutput, and calculate the brightness from the frame. However, the camera is constantly adjusting its exposure settings to compensate for brightness, which makes perfect sense for recording video, but prevents me from getting actual brightness values.
For example, if I put my finger over the camera, the brightness value drops to 0 quickly, but then after a few seconds it creeps back up again as the camera compensates.
So... is there some way to manually set the exposure and disable the automatic adjustment? I tried setting AVCaptureDevice.exposureMode, but it didn't seem to make any difference.
Or, is there a way to get the exposure information from the capture output somehow, so I can appropriately bias my brightness calculation?
UPDATE: I was able to get the EXIF information this way; now I just need to figure out how to bias my brightness calculation.
NSDictionary* dict = (NSDictionary*) CMGetAttachment(sampleBuffer, kCGImagePropertyExifDictionary, NULL);
NSString* exp = [nsDict objectForKey:@"ExposureTime"];
iOS devices use an ambient light sensor to adjust brightness levels based on the light conditions around you. The sensor lowers brightness in dark locations and raises brightness in light locations. The auto-brightness feature is on by default.
iPhone adjusts the screen brightness for current light conditions using the built-in ambient light sensor. Go to Settings > Accessibility. Tap Display & Text Size, then turn on Auto-Brightness.
Apple moved the proximity sensor, previously part of the sensor family within the Face ID notch, under the display and below the main cameras, making the required cutout size smaller. This in turn allows for the iPhone 14 Pro models' new Dynamic Island notification/activities alert system.
According to TechCrunch's Matthew Panzarino, all iPhone 14 models are equipped with a new ambient light sensor on the back of the devices, whereas previous iPhone models only have a single ambient light sensor above the display.
Did you remember to call lockForConfiguration
before setting the exposure mode?
You can access a variety of metadata using CVBufferGetAttachment
on the pixel buffer you can get from the sample buffer; it probably includes the exposure status.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With