我使用了Tesseract OCR iOS扫描文本,并且已经将其与项目中包含的照片配合使用。
但是,当传递一个UIImage从UIImagePickerController时,它就无法工作。我设置了这个简单的测试:
1. 从选择器中获取原始图像,并将其提供给tesseract:不起作用。 2. 将UIImage保存为JPEG,从应用程序容器中复制它,在项目中包含它并将其提供给tesseract:不起作用。 3. 在Photoshop中打开保存的UIImage,并再次保存(使用默认JPEG质量12设置没有更改)。在项目中包含它并将其提供给tesseract:起作用??
Tesseract确实识别出原始图像中正确数量的行,但是结果却是垃圾(我测试了几个示例测试)。一旦在Photoshop中保存图像,它就具有良好的识别率。
我简直无法弄清楚原始UIImage出了什么问题,而Photoshop则可以修复它。请帮忙!这里是图片:
但是,当传递一个UIImage从UIImagePickerController时,它就无法工作。我设置了这个简单的测试:
1. 从选择器中获取原始图像,并将其提供给tesseract:不起作用。 2. 将UIImage保存为JPEG,从应用程序容器中复制它,在项目中包含它并将其提供给tesseract:不起作用。 3. 在Photoshop中打开保存的UIImage,并再次保存(使用默认JPEG质量12设置没有更改)。在项目中包含它并将其提供给tesseract:起作用??
Tesseract确实识别出原始图像中正确数量的行,但是结果却是垃圾(我测试了几个示例测试)。一旦在Photoshop中保存图像,它就具有良好的识别率。
我简直无法弄清楚原始UIImage出了什么问题,而Photoshop则可以修复它。请帮忙!这里是图片:
将图片输入到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];
}
这是从相机获取图像的代码:
- (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];
}
测试两个图像文件:
[self recognizeWithImage:[UIImage imageNamed:@"temp_ocr_image_orig.jpg"]];
[self recognizeWithImage:[UIImage imageNamed:@"temp_ocr_image_photoshopped.jpg"]];