<p>A few weeks ago we <a href="https://ropensci.org/blog/blog/2016/11/16/tesseract">announced</a> the first release of the <a href="https://cran.r-project.org/web/packages/tesseract/index.html">tesseract</a> package: a high quality OCR engine in R. We have now released an update with extra features.</p>
<h2>Installing Training Data</h2>
<p>As explained in the <a href="https://ropensci.org/blog/blog/2016/11/16/tesseract">first post</a>, the tesseract system is powered by language specific training data. By default only English training data is installed. <a href="https://cran.r-project.org/web/packages/tesseract/index.html">Version 1.3</a> adds utilities to make it easier to install additional training data.</p>
<div><pre><code><span># Download French training data</span>
tesseract_download<span>(</span><span>&quot;fra&quot;</span><span>)</span>
</code></pre></div>
<p>Note that this function is not needed on Linux. Here you should install training data via your system package manager instead. For example on Debian/Ubuntu:</p>
<div><pre><code>sudo apt-get install tesseract-ocr-fra
</code></pre></div>
<p>And on Fedora/CentOS you use:</p>
<div><pre><code>sudo yum install tesseract-langpack-fra
</code></pre></div>
<p>Use <code>tesseract_info()</code> to see which training data are currently installed.</p>
<h2>OCR Engine Parameters</h2>
<p>Tesseract supports many <a href="http://www.sk-spell.sk.cx/tesseract-ocr-parameters-in-302-version">parameters</a> to fine tune the OCR engine. For example you can limit the possible characters that can be recognized.</p>
<div><pre><code>engine <span>&lt;-</span> tesseract<span>(</span>options <span>=</span> <span>list</span><span>(</span>tessedit_char_whitelist <span>=</span> <span>&quot;0123456789&quot;</span><span>))</span>
ocr<span>(</span><span>&quot;image.png&quot;</span><span>,</span> engine <span>=</span> engine<span>)</span>
</code></pre></div>
<p>In the example above, Tesseract will only consider numeric characters. If you know in advance the data is numeric (for example an accounting spreadsheet) such options can tremendously improve the accuracy.</p>
<h2>Magick Images</h2>
<p>Tesseract now automatically recognizes images from the awesome <a href="https://cran.r-project.org/web/packages/magick/index.html">magick</a> package (our <a href="https://ropensci.org/blog/blog/2016/08/23/z-magick-release">R wrapper to ImageMagick</a>). This can be useful to preprocess images before feeding to tesseract.</p>
<div><pre><code><span>library</span><span>(</span>magick<span>)</span>
<span>library</span><span>(</span>tesseract<span>)</span>
image <span>&lt;-</span> image_read<span>(</span><span>&quot;http://jeroenooms.github.io/files/dog_hq.png&quot;</span><span>)</span>
image <span>&lt;-</span> image_crop<span>(</span>image<span>,</span> <span>&quot;1700x100+50+150&quot;</span><span>)</span>
<span>cat</span><span>(</span>ocr<span>(</span>image<span>))</span>
</code></pre></div>
<p>We plan to more integration between Magick and Tesseract in future versions.</p>