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

Problem in G8Tesseract.mm #151

Closed alimoeeny closed 9 years ago

alimoeeny commented 9 years ago

In line 803 ( https://github.com/gali8/Tesseract-OCR-iOS/blob/master/TesseractOCR/G8Tesseract.mm#L803 ) I get this error (EXC_BAD_ACCESS (code=1 ...) which I belive is caused by the pixels being emptied if that makes any sense.
As a result, the OCR result comes back empty.

kevincon commented 9 years ago

Can you provide the code (or at least the tesseract-related parts) you're using that triggers this error? What image are you trying to recognize on?

alimoeeny commented 9 years ago

Thanks @kevincon for your reply. I am running the provided example. I run it on iOS 8.1.2 using Xcode 6.2 . I tap on the touch for camera take a photo and see the error "most of the time" which leads to empty results or I see gibberish.

yoiang commented 9 years ago

I'm running into the same issue on device, it's an iPhone 5 with iOS 8.1.3

kevincon commented 9 years ago

Thanks for reporting this issue, guys. It is related to issue #147 and an in-progress pull request #131. Basically, our internal pixForImage method is not taking into account image orientation, so it crashes unless the orientation is "up".

As a quick fix, you can replace the imagePickerController:picker didFinishPickingMediaWithInfo:info method in the Template Framework Project with the code below. That got everything working for me.

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];

    // Redraw the image (if necessary) so it has the corrent orientation:
    if (image.imageOrientation != UIImageOrientationUp) {
        UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
        [image drawInRect:(CGRect){0, 0, image.size}];
        image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }

    [self recognizeImageWithTesseract:image];
}

I know @ws233 and @BamX are still working on the pull request, but we'll make sure to have this fixed before our next CocoaPods release.

kevincon commented 9 years ago

Duplicate of #130.

yoiang commented 9 years ago

@kevincon Awesome, thanks for the follow up :)