title: Digital camera algorithms
body: <p>I'm working on a simple video device and I'd like to introduce some standard cool camera features. Amongst all I'd like to introduce</p>
  
  <ul>
  <li>Focus indicator</li>
  <li>Auto focus</li>
  <li>Auto exposure (ideal exposure time estimation)</li>
  </ul>
  
  <p>Right now I'm looking for some examples, how these features can be implemented. Do you have any useful links?</p>
  
  <p>EDIT :
  Ok, I will use standard CCD camera, which can provide me ~ 20fps in ~1MPix resolution. I'm planning to write it in C#, in case of performance issues, I'll use C++. I'll have lens + CCD camera + motor. </p>
  
  <p>EDIT :
  I'd like to see some more detailed algorithm description. I'm sure some have to be taught in university courses, but I have troubles finding some. For focus indicator I've tried a primitive approach, but in some cases it failed.</p>
  
  <pre><code> int verticalPoints = 0, horizontalPoints = 0;
   ///Calculate the vertical differences
   for (int x = 0; x &lt; toAnalyze.Width; x++)
   {
       for (int y = 1; y &lt; toAnalyze.Height; y++)
       {
          byte* pixel = (byte*)data.Scan0 + y * stride + x;
          verticalDiff += Math.Abs(*pixel - *(pixel - stride));;
       }         
    }
    verticalDiff /= toAnalyze.Width * (toAnalyze.Height-1);
    ///Calculate horizontal differences
    for (int y = 0; y &lt; toAnalyze.Height; y++)
    {
       for (int x = 1; x &lt; toAnalyze.Width; x++)
       {
          byte* pixel = (byte*)data.Scan0 + y * stride + x;
          horizontalDiff += Math.Abs(*pixel - *(pixel - 1));
       }
     }
     horizontalDiff /= (toAnalyze.Width-1) * toAnalyze.Height;
     ///And return the average value
     return(verticalDiff + horizontalDiff) / 2;
  </code></pre>
  
  <p>Thanks</p>