Tesseract OCR - 哪个坐标对于setRect:(CGRect)是正确的?

时间:2014-08-12 08:31:49

标签: ios objective-c ocr tesseract

我想用Tesseract OCR扫描文本(仅限数字)。我在我的UIImagePicker(相机)上放了一个叠加层。这是叠加层的nib文件

Nib

白框是"扫描区域",用户将文本放置在扫描区域。 Box具有以下坐标值:

Coordinates

我在setRect:(CGRect)

中加入了这些坐标
-(void)recognizeImageWithTesseract:(UIImage *)img
{

  dispatch_async(dispatch_get_main_queue(), ^{
    [self.activityIndicator startAnimating];
    [self.toCameraButton setEnabled:NO];
  });


  [self.tesseract setImage:[img blackAndWhite]]; //image to check
  NSLog(@"Breite: %f / Höhe: %f",img.size.width, img.size.height);


  [self.tesseract setRect:CGRectMake(0, 293, 320, 36)]; //optional: set the rectangle to recognize text in the image
  [self.tesseract recognize];


  NSString *recognizedText = [self.tesseract recognizedText];

  NSLog(@"TEXT: %@", recognizedText);

  dispatch_async(dispatch_get_main_queue(), ^{
    [self.activityIndicator stopAnimating];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tesseract OCR iOS" message:recognizedText delegate:nil cancelButtonTitle:@"Yeah!" otherButtonTitles:nil];
    [alert show];
    [self.toCameraButton setEnabled:YES];
    [self.imageView setImage:[img blackAndWhite]];

  });
}

然而,识别的文本总是错误的,我想我使用setRect函数传递了错误的坐标。

1 个答案:

答案 0 :(得分:0)

矩形应该与图像有关;不是“扫描区域”的屏幕。从相机捕获的尺寸将远远大于手机的屏幕。

解决此问题的最佳方法是将屏幕尺寸映射到捕获图像大小。