Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using iPhone camera as brightness sensor

Tags:

ios

iphone

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"];
like image 435
leremjs Avatar asked Jun 14 '11 18:06

leremjs


People also ask

Can I use my iPhone as a light sensor?

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.

How do I turn on the light sensor on my iPhone?

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.

Does iPhone 14 have proximity sensor?

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.

Where is the ambient light sensor on an iPhone?

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.


1 Answers

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.

like image 88
LaC Avatar answered Sep 28 '22 17:09

LaC