title: Tesseract OCR w/ iOS & Swift returns error or gibberish
body: <p>I used this tutorial to get Tesseract OCR working with Swift: <a href="http://www.piterwilson.com/blog/2014/10/18/minimal-tesseact-ocr-setup-in-swift/" rel="nofollow">http://www.piterwilson.com/blog/2014/10/18/minimal-tesseact-ocr-setup-in-swift/</a></p>
  
  <p>It works fine if I upload the demo image and call</p>
  
  <pre><code> tesseract.image = UIImage(named: "image_sample.jpg");
  </code></pre>
  
  <p>But if I use my camera code and take a picture of that same image and call</p>
  
  <pre><code> tesseract.image = self.image.blackAndWhite();
  </code></pre>
  
  <p>the result is either gibberish like</p>
  
  <p>s I 5E251 :Ec
  ‘-. —7.//:E*é«§
  a g :_{:7 IC‘
  J 7 iii—1553‘
  : ﬁzzle —‘;-—:</p>
  
  <p>; ~:~./: -:-‘-</p>
  
  <p>‘- :~£:': _-'~‘:</p>
  
  <p>: 37%; §:‘—_</p>
  
  <p>: ::::E 7,;.
  1f:,:~ ——,</p>
  
  <p>Or it returns a BAD_EXC_ACCESS error. I haven't been able to reproduce the reasoning behind why it gives the error or the gibberish. This is the code of my camera capture (photo taken()) and the processing step (nextStepTapped()):</p>
  
  <pre><code> @IBAction func photoTaken(sender: UIButton) {
  
      var videoConnection = stillImageOutput.connectionWithMediaType(AVMediaTypeVideo)
  
      if videoConnection != nil {
  
          // Show next step button
          self.view.bringSubviewToFront(self.nextStep)
          self.nextStep.hidden = false
  
          // Secure image
          stillImageOutput.captureStillImageAsynchronouslyFromConnection(videoConnection) {
              (imageDataSampleBuffer, error) -&gt; Void in
                  var imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
  
                  self.image = UIImage(data: imageData)
  
                  //var dataProvider = CGDataProviderCreateWithCFData(imageData)
                  //var cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, kCGRenderingIntentDefault)
                  //self.image = UIImage(CGImage: cgImageRef, scale: 1.0, orientation: UIImageOrientation.Right)
  
          }
  
          // Freeze camera preview
          captureSession.stopRunning()
  
      }
  
  }
  
  @IBAction func nextStepTapped(sender: UIButton) {
  
      // Save to camera roll &amp; proceeed
      //UIImageWriteToSavedPhotosAlbum(self.image.blackAndWhite(), nil, nil, nil)
      //UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil)
  
      // OCR
  
      var tesseract:Tesseract = Tesseract();
      tesseract.language = "eng";
      tesseract.delegate = self;
      tesseract.image = self.image.blackAndWhite();
      tesseract.recognize();
  
      NSLog("%@", tesseract.recognizedText);
  
  }
  </code></pre>
  
  <p>The image saves to the Camera Roll and is completely legible if I uncomment the commented lines. Not sure why it won't work. It has no problem reading the text on the image if it's uploaded directly into Xcode as a supporting file, but if I take a picture of the exact same image on my screen then it can't read it.</p>