Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check light intensity using iPhone camera

Tags:

ios

iphone

Is there any way to check the light intensity using iPhone? Does API allows to do this?

like image 735
Nips Avatar asked Jul 28 '11 07:07

Nips


2 Answers

Obtaining Luminosity from an iOS Camera

like image 175
user293895 Avatar answered Oct 18 '22 17:10

user293895


I suppose you can easily do this yourself:

  1. take a still => UIImage.
  2. convert the UIImage to a CGImageRef (UIImage.CGImage).
  3. Now, read every pixel's color and perform such code: x += (red + green + blue) / 3.f;
  4. Calculate the average brightness: avg = x / numberOfPixels;.

avg will now give you a float indicating the average brightness of the still. Most of the time (if not always), this will be identical to the light intensity.

like image 30
cutsoy Avatar answered Oct 18 '22 18:10

cutsoy