<p>At the moment the Amazon Textract does not support font recognition. These two projects might help you:</p>
<ol>
<li>DeepFont: Identify Your Font from An Image</li>
</ol>
<ul>
<li>Paper: <a href="https://arxiv.org/pdf/1507.03196v1.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1507.03196v1.pdf</a></li>
<li>GitHub: <a href="https://github.com/robinreni96/Font_Recognition-DeepFont" rel="nofollow noreferrer">https://github.com/robinreni96/Font_Recognition-DeepFont</a></li>
</ul>
<ol start="2">
<li>Typefont: The first open-source library that detects the font of a text in a image.(It's read only now.)</li>
</ol>
<ul>
<li>GitHub: <a href="https://github.com/Vasile-Peste/Typefont" rel="nofollow noreferrer">https://github.com/Vasile-Peste/Typefont</a></li>
</ul>
How to get the font style from an image with text?
<p>I am using the <code>Amazon Textract API</code>, through AWS' Python API, to extract text from a document (<code>pdf</code> or <code>jpg</code>). I do get the text and coordinates of its bounding box, but I would also love to have the font type (only the major ones needed: Arial, Helvetica, Verdana, Calibri, Times New Roman + a few others).</p>
<p>Does anyone have a solution to get that piece of data?</p>
<p>The best solution may be a package, which accepts a small image, returns the font type name, and which I can run on my server. An external API would most likely be too costly (money and time-wise), as I have to run it 100+ times in a second.</p>
<h3>What Amazon Textract returns (unfortunately, no font type):</h3>
<pre><code>{'BlockType': 'LINE',
 'Confidence': 99.81985473632812,
 'Text': 'This is a text',
 'Geometry': {'BoundingBox': {'Width': 0.7395017743110657,
   'Height': 0.012546566314995289,
   'Left': 0.12995509803295135,
   'Top': 0.2536422610282898},
  'Polygon': [{'X': 0.12995509803295135, 'Y': 0.2536422610282898},
   {'X': 0.8694568872451782, 'Y': 0.2536422610282898},
   {'X': 0.8694568872451782, 'Y': 0.2661888301372528},
   {'X': 0.12995509803295135, 'Y': 0.2661888301372528}]},
 'Id': '59f42615-7f33-41d2-9f3c-77ae5e4b6e7a',
 'Relationships': ...}
</code></pre>
<h3>What I did so far</h3>
<p>I implemented a solution which calculates the ratio <code>width/height</code> of the text and compare this by programmatically drawing the same text using Python's pillow package and different font types and then comparing the ratio. However, that heuristic often leads to wrong results.</p>