title: How do I segment a document using Tesseract then output the resulting bounding boxes and labels
body: <p>I'm trying to get Tesseract to output a file with labelled bounding boxes that result from page segmentation (pre OCR). I know it must be capable of doing this 'out of the box' because of the results shown at the ICDAR competitions where contestants had to segment and various documents (<a href="http://www.prima.cse.salford.ac.uk/www/assets/papers/ICDAR2013_Antonacopoulos_HNLA2013.pdf" rel="noreferrer">academic paper here</a>). Here's an example from that paper illustrating what I want to create:
  <img src="https://i.stack.imgur.com/tmyjJ.png" alt="Image of segmented and labelled output"></p>
  
  <p>I have built the latest version of tesseract using brew, <code>brew install tesseract --HEAD</code>, and have been trying to edit config files located in <code>/usr/local/Cellar/tesseract/HEAD/share/tessdata/configs/</code> to output labelled boxes. The output received using <code>hocr</code> as the config, i.e.</p>
  
  <pre><code>tesseract infile.tiff outfile_stem -l eng -psm 1 hocr
  </code></pre>
  
  <p>gives a bounding box for everything and has some labelling in <code>class</code> tags e.g.</p>
  
  <pre><code>&lt;p class='ocr_par' dir='ltr' id='par_5_82' title="bbox 2194 4490 3842 4589"&gt;
      &lt;span class='ocr_line' id='line_5_142' ...
  </code></pre>
  
  <p>but I can't visualise this. Is there a standard tool to visualize hOCR files, or is the facility to create an output file with bounding boxes built into Tesseract?</p>
  
  <p>The current head version details:</p>
  
  <pre><code>tesseract 3.04.00
   leptonica-1.71
    libjpeg 8d : libpng 1.6.16 : libtiff 4.0.3 : zlib 1.2.5
  </code></pre>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>I'm really looking to achieve this using the command line tool (as in examples above). @nguyenq has pointed me to the <a href="https://code.google.com/p/tesseract-ocr/wiki/APIExample" rel="noreferrer">API reference</a>, unfortunately I have no c++ experience. If the only solution is to use the API, please can you provide a quick python example?</p>