title: Algorithm for LED light detection using android phone's camera
body: <p>I'm trying to detect the status of an LED light using an android phone's camera.
  The camera app is using the onpreviewframe method to take each frame and using the luma part of the YUV file (each frame taken is saved in a buffer as a YUV file, the first width*height bytes of YUV are the luma part and include the grayscale of the corresponding pixels, I work with those bytes to make a decision).</p>
  
  <p>Currently with each frame I calculate the grayscale mean and compare it with a threshold number to decide if the bit is an 0 or a 1; I'm creating the threshold number by getting the grayscale mean of the first 50 frames.
  This algorithm is too simple and weak to hold in different situations and I'm looking to make it more robust.</p>
  
  <p>I have seen a few questions regarding my problem (**) but non of them asks for an actual algorithm which is what I'm looking for as I am new to image processing.</p>
  
  <p>My questions - </p>
  
  <ol>
  <li><p>What algorithms should I implement for a better decision making?</p></li>
  <li><p>How (if needed) to create a more precise threshold number?</p></li>
  <li><p>Are there any sources I can use (preferably in java)?</p></li>
  </ol>
  
  <p>*The LED is fixed and the phone is handheld.</p>
  
  <p>**<a href="https://stackoverflow.com/questions/1365234/opencv-detect-blinking-lights-in-a-video-feed">OpenCV: Detect blinking lights in a video feed</a> &amp; <a href="https://stackoverflow.com/questions/8877228/opencv-detect-blinking-lights">openCV detect blinking lights</a></p>