Tesseract OCR仅显示随机字母

时间:2017-09-19 14:55:46

标签: objective-c tesseract

我使用实时相机更新方法在我的iOS应用程序中实现Tesseract OCR

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection

我将输入图像传递为

UIImage *image = [GMVUtility sampleBufferTo32RGBA:sampleBuffer];
[self recognizeImageWithTesseract:image];
-(void)recognizeImageWithTesseract:(UIImage *)image {

    operationQueue = [[NSOperationQueue alloc] init];

    // Create a new `G8RecognitionOperation` to perform the OCR asynchronously
    // It is assumed that there is a .traineddata file for the language pack
    // you want Tesseract to use in the "tessdata" folder in the root of the
    // project AND that the "tessdata" folder is a referenced folder and NOT
    // a symbolic group in your project
    G8RecognitionOperation *operation = [[G8RecognitionOperation alloc] initWithLanguage:@"eng+ita"];

    operation.tesseract.engineMode = G8OCREngineModeTesseractOnly;

    // Let Tesseract automatically segment the page into blocks of text
    // based on its analysis (see G8Constants.h) for other page segmentation
    // mode options
    operation.tesseract.pageSegmentationMode = G8PageSegmentationModeAutoOnly;

    operation.tesseract.maximumRecognitionTime = 6.0;

    operation.delegate = self;

    operation.tesseract.charWhitelist = @"01234567890/qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";


    operation.tesseract.image = image;

    [operation.tesseract  recognize];


    operation.recognitionCompleteBlock = ^(G8Tesseract *tesseract) {

        NSString *recognizedText = tesseract.recognizedText;

        NSLog(@"%@", recognizedText);

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OCR Result"
                                                        message:recognizedText
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    };

    self.takePictureButton.imageView.image = operation.tesseract.thresholdedImage;

    [operationQueue addOperation:operation];
}

NSString *recognizedText = tesseract.recognizedText;

即使在简单图像上,RecognText也会显示随机字母和数字。

任何人都可以帮我解决什么错误吗?

PS:附上我的tessdata

Screenshot for tessdata

0 个答案:

没有答案