<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/tesseract-update-options-and-languages/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://ropensci.org/blog/technotes/2016/12/08/tesseract-13"> rOpenSci Blog - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A few weeks ago we <a target="_blank" rel="nofollow" href="https://ropensci.org/blog/blog/2016/11/16/tesseract">announced</a> the first release of the <a target="_blank" rel="nofollow" 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 target="_blank" rel="nofollow" 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 target="_blank" rel="nofollow" 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 data-lang="r"><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 data-lang="sh">sudo apt-get install tesseract-ocr-fra
</code></pre>
</div>
<p>And on Fedora/CentOS you use:</p>
<div>
<pre><code data-lang="sh">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 target="_blank" rel="nofollow" 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 data-lang="r">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 target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/magick/index.html">magick</a> package (our <a target="_blank" rel="nofollow" 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 data-lang="r"><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>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://ropensci.org/blog/technotes/2016/12/08/tesseract-13"> rOpenSci Blog - R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/n9z90wfP1F4"></a></div>