如何使用OCR识别图像中的文本

时间:2014-02-24 08:19:41

标签: ios uiimagepickercontroller ocr tesseract

我一直在使用Tesseract OCR来识别图像中的文字。它与我的资源包中的图像一起正常工作,但是如果我使用UIImagePickerController拍摄照片并使用该照片来识别文本,那么它就不合适并且会获得许多特殊字符。

我使用Tesseract从图像中获取文本的工作代码:

Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"];                
[tesseract setImage:[UIImage imageNamed:@"112233.jpg"]];
[tesseract recognize];
NSLog(@" the image text is  ===\n\n\n \t %@", [tesseract recognizedText]); 

但是在识别捕获图像中的文本时,相同的代码无效:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     UIImage *origiImage=[info objectForKey:UIImagePickerControllerOriginalImage];
     Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata"   language:@"eng"];
     [tesseract setImage:origiImage];
     [tesseract recognize];
     NSLog(@" the image text is  ===\n\n\n \t %@", [tesseract recognizedText]);

0 个答案:

没有答案