I used Tesseract OCR iOS to scan the text, and I got it to work with the photograph included in the project.
But when passing UIImage from UIImagePickerController, this will not work. I installed this simple test:
- Take the original image from the collector and submit it to tesseract: Does not work .
- Save the UIImage as a JPEG, copy it from the application container, include it in the project and submit it to tesseract: It does not work .
- Open the saved UIImage in Photoshop and save it again (no change with the default JPEG quality settings of 12). Include it in the project to submit it to tesseract: Works?!?
Tesseract recognizes the correct number of lines in the original, but as garbage (I tested a few test cases). After saving in Photoshop, the image has a good recognition speed.
I just can’t understand what’s wrong with the original UIImage, which Photoshop somehow fixes. Please, help!
Here are the images:
Code for submitting images to tesseract:
- (void)recognizeWithImage:(UIImage *)image { G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] initWithLanguage:@"dan"]; operation.tesseract.image = image; self.imageView.image = image; operation.recognitionCompleteBlock = ^(G8Tesseract *recognizedTesseract) { NSLog(@"Result:\n%@", [recognizedTesseract recognizedText]); }; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [queue addOperation:operation]; }
Here is the code to get the image from the camera:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:nil]; UIImage *originalImage = info[UIImagePickerControllerOriginalImage]; NSData *dataForJPEGFile = UIImageJPEGRepresentation(originalImage, 1.0); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *filePath = [paths[0] stringByAppendingPathComponent:@"temp_ocr_image_orig.jpg"]; [dataForJPEGFile writeToFile:filePath atomically:YES]; [self recognizeWithImage:originalImage]; }
And testing two image files:
[self recognizeWithImage:[UIImage imageNamed:@"temp_ocr_image_orig.jpg"]]; [self recognizeWithImage:[UIImage imageNamed:@"temp_ocr_image_photoshopped.jpg"]];
source share