title: how to detect words in an image with OpenCV and Tesseract properly
body: <p>I'm working on an application which reads an image file with OpenCV and processes the words on it with Tesseract.
  With the following code Tesseract detects extra rectangles which don't contain text.</p>
  <pre><code>void Application::Application::OpenAndProcessImageFile(void)
  {
      OPENFILENAMEA ofn;
      ZeroMemory(&amp;ofn, sizeof(OPENFILENAMEA));
  
      char szFile[260] = { 0 };
      // Initialize remaining fields of OPENFILENAMEA structure
      ofn.lStructSize     = sizeof(ofn);
      ofn.hwndOwner       = mWindow-&gt;getHandle();
      ofn.lpstrFile       = szFile;
      ofn.nMaxFile        = sizeof(szFile);
      ofn.lpstrFilter     = &quot;JPG\0*.JPG\0PNG\0*.PNG\0&quot;;
      ofn.nFilterIndex    = 1;
      ofn.lpstrFileTitle  = NULL;
      ofn.nMaxFileTitle   = 0;
      ofn.lpstrInitialDir = NULL;
      ofn.Flags           = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  
      //open the picture dialog and select the image
      if (GetOpenFileNameA(&amp;ofn) == TRUE) {
          std::string filePath = ofn.lpstrFile;
          
          //load image
          mImage = cv::imread(filePath.c_str());
  
          //process image     
          tesseract::TessBaseAPI ocr = tesseract::TessBaseAPI();
  
          ocr.Init(NULL, &quot;eng&quot;);
          ocr.SetImage(mImage.data, mImage.cols, mImage.rows, 3, mImage.step);
  
          Boxa* bounds = ocr.GetWords(NULL);
          for (int i = 0; i &lt; bounds-&gt;n; ++i) {
              Box* b = bounds-&gt;box[i];
              cv::rectangle(mImage, { b-&gt;x,b-&gt;y,b-&gt;w,b-&gt;h }, { 0, 255, 0 }, 2);
          }
  
          ocr.End();
          
          //show image
          cv::destroyAllWindows();
          cv::imshow(&quot;İşlenmiş Resim&quot;, mImage);
      }
  }
  </code></pre>
  <p>And here is the output image</p>
  <p><a href="https://i.stack.imgur.com/25Owx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/25Owx.png" alt="enter image description here" /></a></p>
  <p>As you can see Tesseract processes areas which don't contain words at all.
  How can I fix this?</p>