2

我正在学习如何使用 Tesseract API,我对 hOCR 输出函数很感兴趣。目前我正在使用此代码扫描图像。

 Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"eng"];
tesseract.delegate = self;
[tesseract setVariableValue:@"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.-():" forKey:@"tessedit_char_whitelist"];
[tesseract setVariableValue:@"0" forKey:@"tessedit_create_hocr"];

UIImage *image = [UIImage imageNamed:@"card.jpg"];

CGFloat newWidth = 1200;
CGSize newSize = CGSizeMake(newWidth, newWidth);
image = [image resizedImage:newSize interpolationQuality:kCGInterpolationHigh];


[tesseract setImage:image]; //image to check
[tesseract recognize];

 NSLog(@"Here is the text %@", [tesseract recognizedText]);

一切都编译得很好,但我想知道如何存储 hOCR 函数返回的 .html 。我可以将它存储在变量中吗?生成该文件后,我需要能够在我的程序中访问该文件。任何有关如何在 iOS 上使用 hOCR 的见解都值得赞赏。

4

1 回答 1

0

You are getting an NSString if you proceed as follows.

- (NSString *)getHOCRText {
        char *boxtext = _tesseract->GetHOCRText(0);
        return [NSString stringWithUTF8String:boxtext];
}

Later you can convert this NSString to NSData.

    NSData *xmlData = [xmlString dataUsingEncoding:NSASCIIStringEncoding];

So that you can parse this data using NSXMLParser

        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];

Hope you are aware remaining parsing procedures.

于 2014-02-05T11:09:53.473 回答