2

私は本当にあなたの助けが必要です.Xcodeでプログラムを実行し、成功しましたが、後で、

次のエラーが表示されます: **スレッド 1: プログラムがシグナルを受信しました:"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

imageDataここで NULL でないことを確認してください。それが、あなたが見ているものの最も一般的な原因です。タイトルを問題にもっと関連するものに再検討し、スタックトレースと に渡すすべての変数に焦点を当てる必要がありますTesseractRect()

もう 1 つの主な可能性は、tess(それが何であれ) ポインターが正しくないか、正しい C++ クラスの一部ではないことです (これは Objective-C++ であると想定していますが、そのいずれについても明確ではありません)。

于 2011-09-13T02:27:04.340 に答える
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 に答える