title: Detecting Glare in image
body: <p>I am adding a card scanning feature to my iOS app and trying to add glare detection. So when a glare is detected while scanning, user is prompted to reposition the card.</p>
  
  <p>I have tried implementing it with OpenCV using 
  <a href="https://www.pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/" rel="nofollow noreferrer">https://www.pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/</a></p>
  
  <p><a href="https://www.pyimagesearch.com/2014/09/29/finding-brightest-spot-image-using-python-opencv/" rel="nofollow noreferrer">https://www.pyimagesearch.com/2014/09/29/finding-brightest-spot-image-using-python-opencv/</a></p>
  
  <p><a href="https://stackoverflow.com/questions/51846933/finding-bright-spots-in-a-image-using-opencv">Finding bright spots in a image using opencv</a></p>
  
  <p>But considering I have very less background knowledge in OpenCV and computer vision, I am unable to get desired results.</p>
  
  <p>Kindly guide me in right direction on how can I achieve glare detection using OpenCV/CoreImage/GPUImage.</p>
  
  <p>My code so far</p>
  
  <pre><code>+ (bool) imageHavingGlare:(CMSampleBufferRef)buffer {
   cv::Mat matImage = [OpenCVWrapper matFromBuffer:buffer];
   cv::Mat matImageGrey;
   cv::cvtColor(matImage, matImageGrey, CV_BGRA2GRAY);
  
   GaussianBlur(matImageGrey, matImageGrey, cvSize(11,11), 0);
  
   cv::Mat matImageBinarized;
   cv::threshold(matImageGrey, matImageBinarized, 30, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
  
   double min, max;
   cv::Point min_loc, max_loc;
   cv::minMaxLoc(matImageBinarized, &amp;min, &amp;max, &amp;min_loc, &amp;max_loc);    
  
   if(((max_loc.x &gt; 0) &amp;&amp; (max_loc.y &gt; 0)))
   {
      return true;
   }
  
   return false;
  }
  </code></pre>