Tesseract OCR shows random alphabets only

63 views
Skip to first unread message

adeel...@purelogics.net

unread,
Sep 21, 2017, 6:55:40 AM9/21/17
to tesseract-ocr
I'm implementing Tesseract OCR in my iOS application using real time camera update method 

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

I am passing the input image as 

    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;

The recognizedText shows random alphabets and numbers even on simple image.

Can anyone please help me out whats wrong?

PS: attached my tessdata 





Reply all
Reply to author
Forward
0 new messages