title: Passing image with OpenCV bounding boxes to tesseract OCR
body: <p>I'm trying to extract text from image using OpenCV and Tesseract. I've managed to detect the text areas and use bounding boxes to delimit them. But now I can't find how to pass the bounding boxes to Tesseract. </p>
  
  <pre><code>        for(int idx = 0; idx &gt;= 0; idx = hierarchy[idx][0])
          {
              Rect rect = boundingRect(contours[idx]);
              Mat maskROI(mask, rect);
              maskROI = Scalar(0, 0, 0);
              // fill the contour
              drawContours(mask, contours, idx, Scalar(255, 255, 255), CV_FILLED);
              // ratio of non-zero pixels in the filled region
              double r = (double)countNonZero(maskROI)/(rect.width*rect.height);
  
              if (r &gt; .45 /* assume at least 45% of the area is filled if it contains text */
                  &amp;&amp;
                  (rect.height &gt; 8 &amp;&amp; rect.width &gt; 8) /* constraints on region size */
                  /* these two conditions alone are not very robust. better to use something
                   like the number of significant peaks in a horizontal projection as a third condition */
                  )
              {
                  rectangle(rgb, rect, Scalar(0, 255, 0), 2);
              }
          }
          imwrite(OUTPUT_FOLDER_PATH + string("/rgb.jpg"), rgb);
      return 0;
      }
  </code></pre>
  
  <p>I'm getting very good results with the bounding boxes.  Image with bounding boxes:</p>
  
  <p><a href="https://i.stack.imgur.com/tpTQq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tpTQq.jpg" alt="enter image description here"></a></p>
  
  <p>And then tried <code>cv::text::OCRTesseract::run</code> but that doesn't seem to work.</p>
  
  <p>Anyone has an idea?</p>
  
  <p>EDIT: I had to remove most of the code because the company i'm in an internship with asked me to. But this is for my end of the year project so as soon as i end the year i will edit the post with a github link for the whole project.</p>