NSString *retText = @"";
tesseract::ResultIterator *ri = tess.GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_WORD;
if (ri != 0) {
do {
const char *word = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
if (word) {
printf("word: '%s'; \tconf: %.2f; BoundingBox: %d,%d,%d,%d;\n", word,
conf, x1, y1, x2, y2);
NSString *temp =
[NSString stringWithCString:word encoding:NSUTF8StringEncoding];
retText = [NSString stringWithFormat:@"%@ %@", retText, temp];
retText = [retText stringByReplacingOccurrencesOfString:@"[\\\""
withString:@""];
retText = [retText stringByReplacingOccurrencesOfString:@"\n\n"
withString:@""];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(x1, y1)];
[path addLineToPoint:CGPointMake(x2, y1)];
[path addLineToPoint:CGPointMake(x2, y2)];
[path addLineToPoint:CGPointMake(x1, y2)];
[path addLineToPoint:CGPointMake(x1, y1)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor clearColor] CGColor];
[self.scrollView.layer addSublayer:shapeLayer];
delete[] word;
}
} while (ri->Next(level));
}