gali8 / Tesseract-OCR-iOS

Tesseract OCR iOS is a Framework for iOS7+, compiled also for armv7s and arm64.
http://www.nexor.it
MIT License
4.22k stars 949 forks source link

imageWithBlocks fix. Rotate the original image to the right or it sho… #259

Closed sunshineo closed 8 years ago

sunshineo commented 8 years ago

…ws upside down.

sunshineo commented 8 years ago

Maybe this is my own problem. When I use the library, I have to rotate the image left before pass to it.

let image2: UIImage = UIImage(CGImage: imageRef, scale: image.scale, orientation: UIImageOrientation.Left)

Otherwise, it cannot recognize properly. I'm taking a photo with iphone vertically, so maybe that is the problem. I only realized this after I created the pull request.

ws233 commented 8 years ago

@sunshineo, as I remember, the framework can rotate images if they contain the rotation info. Do you do any image preprocessing, which removes rotation info from the image?

sunshineo commented 8 years ago

@ws233 No pre-processing. Straight out of the camera and into Tesseract. It did not work at first at all. Later I discovered that if I took the picture horizontally and pass to Tesseract it works. So since my app will always took the picture vertically (My app does not have a horizontal mode), I programmatically rotated it left as shown above in the Swift code. And then I ran into this problem when I try to use imageWithBlocks. All the blocks are in the right place, but the image is upside down, unless I do that fix to rotate it right.

sunshineo commented 8 years ago

I just discovered that if the thresholded is set to true, this rotation is not needed. I'm going to close this one and create a new pull request.

ws233 commented 8 years ago

The issue is that nevermind of the orientation of the device, the pixels in the image are always located in the same order. Only the imageOriantation tells how to draw the image on the screen. imageWithBlocks doesn't consider the imageOriantation property of the image. So you'd better fix the drawing code there. In the case of the thresholding, the image is preprocessed for you automatically. And if I remember correctly, the preprocessing considers the imageRotation. Therefore you have a correct result after the preprocessing.

sunshineo commented 8 years ago

Hi @ws233 , could you help me understand your comments? The imageOriantation is a property on UIImage? By "So you'd better fix the drawing code there.", where do you mean exactly? The imageWithBlocks function?

Thank you very much!

ws233 commented 8 years ago

Yes it's. Twice :)

sunshineo commented 8 years ago

Thank you! I'm copying your comments to the newer pull request I created.

ws233 commented 8 years ago

You may work in this PR if you wish