OpenCV for OCR: How to compute thresholding levels for gray image OCR
<p>I'm trying to prepare images for OCR, and so far here is what I've done using info from <a href="https://stackoverflow.com/questions/23506105/extracting-text-opencv">Extracting text OpenCV</a></p>

<p>From the resulting image I use the contours that have been filtered to make a mask as follow:</p>

<pre><code>//this is the mask of all the text
Mat maskF = Mat::zeros(rgb.rows, rgb.cols, CV_8UC1);
// CV_FILLED fills the connected components found - CV_FILLED to fill
drawContours(maskF, letters, -1, Scalar(255), CV_FILLED);
cv::imwrite("noise2-Mask.png", maskF);
</code></pre>

<p>the resulting img is promising:<a href="https://i.stack.imgur.com/2iins.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2iins.png" alt="enter image description here"></a></p>

<p>considering this was my original img:<a href="https://i.stack.imgur.com/R39OP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R39OP.jpg" alt="enter image description here"></a></p>

<p>Unfortunately running Tesseract on it yields some issues, I think the levels of gray you see between letters on words confuses tesseract - so, you're thinking yeah, lets do a binary transform, well that just misses the second half of the page, so I tried applying Otsu threshold as well but the text becomes to pixelated and characters lose their shape.</p>

<p>I tried CalcBlockMeanVariance  from <a href="https://stackoverflow.com/questions/22122309/opencv-adaptive-threshold-ocr">OpenCV Adaptive Threshold OCR</a> but could not get it to compile (and I'm not certain I understand it all tbh) compile chokes on </p>

<pre><code>res=1.0-res;
res=Img+res;
</code></pre>

<p>Anyhow, if anyone has any suggestions I'll appreciate it! Note that the fractions are rarely recognized by Tesseract but I'm writing a new training set that will hopefully improve the reco rate)</p>