title: Extracting text OpenCV
body: <p>I am trying to find the bounding boxes of text in an image and am currently using this approach:</p>
  
  <pre><code>// calculate the local variances of the grayscale image
  Mat t_mean, t_mean_2;
  Mat grayF;
  outImg_gray.convertTo(grayF, CV_32F);
  int winSize = 35;
  blur(grayF, t_mean, cv::Size(winSize,winSize));
  blur(grayF.mul(grayF), t_mean_2, cv::Size(winSize,winSize));
  Mat varMat = t_mean_2 - t_mean.mul(t_mean);
  varMat.convertTo(varMat, CV_8U);
  
  // threshold the high variance regions
  Mat varMatRegions = varMat &gt; 100;
  </code></pre>
  
  <p>When given an image like this:</p>
  
  <p><img src="https://i.stack.imgur.com/VfDfJ.png" alt="enter image description here"></p>
  
  <p>Then when I show <code>varMatRegions</code> I get this image:</p>
  
  <p><img src="https://i.stack.imgur.com/64wu4.png" alt="enter image description here"></p>
  
  <p>As you can see it somewhat combines the left block of text with the header of the card, for most cards this method works great but on busier cards it can cause problems. </p>
  
  <p>The reason it is bad for those contours to connect is that it makes the bounding box of the contour nearly take up the entire card.</p>
  
  <p>Can anyone suggest a different way I can find the text to ensure proper detection of text?</p>
  
  <p><strong>200 points to whoever can find the text in the card above the these two.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/7h4SJ.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/8ipeJ.jpg" alt="enter image description here"></p>