title: iOS Tesseract: bad results
body: <p>I just started to get my hands dirty with the Tesseract library, but the results are really really bad.</p>
  <p>I followed the instructions in the Git repository ( <a href="https://github.com/gali8/Tesseract-OCR-iOS" rel="noreferrer">https://github.com/gali8/Tesseract-OCR-iOS</a> ). My ViewController uses the following method to start recognizing:</p>
  <pre><code>Tesseract *t = [[Tesseract alloc] initWithLanguage:@&quot;deu&quot;];
  t.delegate = self;
  
  [t setVariableValue:@&quot;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot; forKey:@&quot;tessedit_char_whitelist&quot;];
  [t setImage:img];
  
  [t recognize];
  
  NSLog( @&quot;Recognized text: %@&quot;, [t recognizedText] );
  
  labelRecognizedText.text = [t recognizedText];
  
  t = nil;
  </code></pre>
  <p>The sample image from the project tempalte <a href="https://i.stack.imgur.com/uzxae.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/uzxae.jpg" alt="the sample image" /></a></p>
   
  <p>works well (which tells me that the project itself is setup correctly), but whenever I try to use other images, the recognized text is a complete mess. For example, I tried to take a picture of my finder displaying the sample image:</p>
  <p><a href="https://dl.dropboxusercontent.com/u/607872/tesseract.jpg" rel="noreferrer">https://dl.dropboxusercontent.com/u/607872/tesseract.jpg</a> (1,5 MB)</p>
  <p>But Tesseract recognizes:</p>
  <pre><code>Recognized text: s f l TO  if v   Ysssifss f
  
   ssqxizg ss sfzzlj z
  
  s N T IYIOGY Z I l EY s s
  
  k Es ETL ZHE s UEY
  
  z xhks Fsjs Es z VIII c 
  
  s I   XFTZT c s  h V Ijzs
  
  L s sk  sisijk J
  
  s f s ssj Jss sssHss H VI
  
  s s  H 
  
  i s H st xzs
  s s k 4  is x2 IV
  Illlsiqss sssnsiisfjlisszxiij s
  K
  </code></pre>
  <p>Even when the character whitelist only contains numbers, I don't get a result even close to what the image looks like:</p>
  <pre><code>Recognized text:       3          74 211  
  
      1             
  
           1 1    1    
  
    3  53 379     1  
  
  3  1   33  5    3 2 
        3          9 73
      1  61 2 2  
      3   1  6   5 212   7 
         1 
  4     9 4  
             1  17
   111  11    1 1  11  1 1 1 1
   
  </code></pre>
  <p>I assume there's something wrong with the way fotos are taken from the iPad mini's camera I currently use, but I can't figure out what and why.</p>
  <p>Any hints?</p>
  <hr />
  <p><strong>Update #1</strong></p>
  <p>In response to Tomas:</p>
  <p>I followed the tutorial in your post but encountered several errors along the way...</p>
  <ul>
  <li>the <code>UIImage+OpenCV</code> category cannot be used in my ARC project</li>
  <li>I cannot import <code>&lt;opencv2/...&gt;</code> in my controllers, auto-completion does not offer it (and therefore <code>[UIImage CVMat]</code> is not defined)</li>
  </ul>
  <p>I think there's something wrong with my integration of OpenCV, even though I followed the Hello-tutorial and added the framework. Am I required to build OpenCV on my Mac as well or is it sufficient to just include the framework in my Xcode project?</p>
  <p>Since I don't really know what you might consider as &quot;important&quot; at this point (I've already read several posts and tutorials and tried different steps), feel free to ask :)</p>
  <hr />
  <p><strong>Update #2</strong></p>
  <p>@Tomas: thanks, the ARC-part was essential. My ViewController already has been renamed to <code>.mm</code>. Forget the part about &quot;cannot import opencv2/&quot; since I already included it in my <code>TestApp-Prefix.pch</code> (as stated in the Hello-tutorial).</p>
  <p>On to the next challenge ;)</p>
  <p>I noticed that when I use images taken with the camera, the bounds for the <code>roi</code> object aren't calculated successfully. I played around with the device orientation and put a <code>UIImage</code> in my view to see the image processing steps, but sometimes (even when the image is correctly aligned) the values are negative because the <code>if</code>-condition in the <code>bounds.size()</code>-<code>for</code>-loop isn't met. The worst case I had: minX/Y and maxX/Y were never touched. Long story short: the line starting with <code>Mat roi = inranged(cv::Rect(</code> throws an exception (assertion failed because the values were <code>&lt; 0</code> ). I don't know if the number of contours matter, but I assume so because the bigger the images, the more likely the assertion exception is.</p>
  <p>To be perfectly honest: I haven't had the time to read OpenCV's documentation and understand what your code does, but as of now, I don't think there's a way around. Seems like, unfortunately for me, my initial task (scan receipt, run OCR, show items in a table) requires more resources (=time) than I thought.</p>