2

我真的需要你们的帮助,我在 Xcode 中运行我的程序并且它成功但后来,

它向我显示了这个错误: **线程 1:程序收到信号:在我的程序行上我有**bold的“EXC_BAD_ACCESS”

- (NSString *) ocrImage: (UIImage *) uiImage
{
    CGSize imageSize = [uiImage size];
    double bytes_per_line   = CGImageGetBytesPerRow([uiImage CGImage]);
    double bytes_per_pixel  = CGImageGetBitsPerPixel([uiImage CGImage]) / 8.0;

    CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider([uiImage CGImage]));
    const UInt8 *imageData = CFDataGetBytePtr(data);

    // this could take a while. maybe needs to happen asynchronously.

    **char* text = tess->TesseractRect(imageData,(int)bytes_per_pixel,(int)bytes_per_line, 0, 0,(int) imageSize.height,(int) imageSize.width);**

    // Do something useful with the text!
    NSLog(@"Converted text: %@",[NSString stringWithCString:text encoding:NSUTF8StringEncoding]);

    return [NSString stringWithCString:text encoding:NSUTF8StringEncoding];
}

谢谢你。

4

2 回答 2

0
- (NSString *)readAndProcessImage:(UIImage *)uiImage
{
  CGSize imageSize = [uiImage size];
  int bytes_per_line = (int)CGImageGetBytesPerRow([uiImage CGImage]);
  int bytes_per_pixel = (int)CGImageGetBitsPerPixel([uiImage CGImage]) / 8.0;

  CFDataRef data =
      CGDataProviderCopyData(CGImageGetDataProvider([uiImage CGImage]));
  const UInt8 *imageData = CFDataGetBytePtr(data);

  // this could take a while. maybe needs to happen asynchronously?
  char *text = tess.TesseractRect(imageData, bytes_per_pixel, bytes_per_line, 0,
                                  0, imageSize.width, imageSize.height);

  NSString *textStr = [NSString stringWithUTF8String:text];

  delete[] text;
  CFRelease(data);
  return textStr;
}
于 2014-08-14T05:19:22.657 回答
0

确保imageData这里不为 NULL。这是您所看到的最常见的原因。您应该重新考虑与您的问题更相关的标题,并专注于堆栈跟踪和您传递给的所有变量TesseractRect()

另一个主要的可能性是tess(不管是什么)是一个错误的指针,或者它不是正确 C++ 类的一部分(我假设这是 Objective-C++;你不清楚其中的任何一个)。

于 2011-09-13T02:27:04.340 回答