Code Monkey home page Code Monkey logo

Comments (2)

gali8 avatar gali8 commented on June 26, 2024

Cute avatar! I love limbo :)

You can use the shouldCancelImageRecognitionForTesseract delegate for now.
I'm working for your request.

from tesseract-ocr-ios.

arturdev avatar arturdev commented on June 26, 2024

Haha, thanks :) I love limbo too :)

Actually I'm making an app which must recognize text in "real time".
E.g. something link in this video https://www.youtube.com/watch?v=c7swRRLlYEo :)
Here is my code:

#define kScanTimeInterval 0.5f
//...
- (void)createScanner
{
    self.scanner = nil;
    self.scanner = [[Tesseract alloc] initWithLanguage:@"swe"];
    [self.scanner setVariableValue:@"0123456789# ->,AaBbCcDdEeFfGgIiJjKkLlMmNnOoPpRrSsTtUuVv" forKey:@"tessedit_char_whitelist"];
//    [self.scanner setVariableValue:@"±@$%^§&*+=[]{}'|?~" forKey:@"tessedit_char_blacklist"];
    self.scanner.delegate = self;
    self.grayScaleFilter = [[GPUImageGrayscaleFilter alloc] init];
}

- (void)prepareToScan
{
    self.timer = [[MSWeakTimer alloc] initWithTimeInterval:kScanTimeInterval
                                                    target:self
                                                  selector:@selector(timerTicked)
                                                  userInfo:nil
                                                   repeats:YES
                                             dispatchQueue:dispatch_get_main_queue()];
    [self.timer schedule];    
    [self.captureSession startRunning];
}

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;
{
    if (canScanFrame) {
        canScanFrame = NO;
        UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
        image = [UIImage imageByCropping:image toRect:self.rectForScanning];        
        image = [self.grayScaleFilter imageByFilteringImage:image];

        [self.scanner setImage:image];
        isScanning = YES;

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSLog(@"scan start");
            [self.scanner recognize];
            NSLog(@"scan stop");
            dispatch_async(dispatch_get_main_queue(), ^{
                isScanning = NO;
                NSString *text = [self.scanner recognizedText];
                if (self.delegate && [self.delegate respondsToSelector:@selector(ocrScanner:didScanWithResult:forImage:)]) {
                        [self.delegate ocrScanner:self didScanWithResult:text forImage:image];
                }
            });
        });
    }
}

- (void)timerTicked
{
    if (!isScanning) {
        canScanFrame = YES;
    }
}

In my case I know that the scanning frame are small (because I crop them), and that the text that I'm scanning is also a small text, but sometimes scanning process for 1 specific frame takes a lot of time (~5secs). I don't know, may be because of the camera shakes and the image not much clear to recognize?

Here I thought about setting time out for recognizing time (which in my case should not exceed 1 sec) which will optimise scanning process.

Or, it will be even better, also to set limitation of characters count that must be scanned. Say, I know that the text that user must scan can be max 20 of length, but tesseract returns a lot of symbols (like ~,$± etc) after 5 seconds of recognizing.

So, if I set the timeOut to 1 second, and maxRecognizedTextLength to 20, then the scanning process will be much more faster and accurate :)

from tesseract-ocr-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.