Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:27:49+00:00 2026-06-13T23:27:49+00:00

Before mark as copy or repeat question, please read the whole question first. I

  • 0

Before mark as copy or repeat question, please read the whole question first.

I am able to do at pressent is as below:

  1. To get image and crop the desired part for OCR.
  2. Process the image using tesseract and leptonica.
  3. When the applied document is cropped in chunks ie 1 character per image it provides 96% of accuracy.
  4. If I don’t do that and the document background is in white color and text is in black color it gives almost same accuracy.

For example if the input is as this photo :

Photo start

enter image description here

Photo end

What I want is to able to get the same accuracy for this photoenter image description here
without generating blocks.

The code I used to init tesseract and extract text from image is as below:

For init of tesseract

in .h file

tesseract::TessBaseAPI *tesseract;
uint32_t *pixels;

in .m file

tesseract = new tesseract::TessBaseAPI();
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng");
tesseract->SetPageSegMode(tesseract::PSM_SINGLE_LINE);
tesseract->SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
tesseract->SetVariable("language_model_penalty_non_freq_dict_word", "1");
tesseract->SetVariable("language_model_penalty_non_dict_word ", "1");
tesseract->SetVariable("tessedit_flip_0O", "1");
tesseract->SetVariable("tessedit_single_match", "0");
tesseract->SetVariable("textord_noise_normratio", "5");
tesseract->SetVariable("matcher_avg_noise_size", "22");
tesseract->SetVariable("image_default_resolution", "450");
tesseract->SetVariable("editor_image_text_color", "40");
tesseract->SetVariable("textord_projection_scale", "0.25");
tesseract->SetVariable("tessedit_minimal_rejection", "1");
tesseract->SetVariable("tessedit_zero_kelvin_rejection", "1");

For get text from image

- (void)processOcrAt:(UIImage *)image
{
    [self setTesseractImage:image];

    tesseract->Recognize(NULL);
    char* utf8Text = tesseract->GetUTF8Text();
    int conf = tesseract->MeanTextConf();

    NSArray *arr = [[NSArray alloc]initWithObjects:[NSString stringWithUTF8String:utf8Text],[NSString stringWithFormat:@"%d%@",conf,@"%"], nil];

    [self performSelectorOnMainThread:@selector(ocrProcessingFinished:)
                           withObject:arr
                        waitUntilDone:YES];
    free(utf8Text);
}

- (void)ocrProcessingFinished0:(NSArray *)result
{
    UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"Data" message:[result objectAtIndex:0] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
   [alt show];
}

But I don’t get proper output for the number plate image either it is null or it gives some garbage data for the image.

And if I use the image which is the first one ie white background with text as black then the output is 89 to 95% accurate.

Please help me out.

Any suggestion will be appreciated.

Update

Thanks to @jcesar for providing the link and also to @konstantin pribluda to provide valuable information and guide.

I am able to convert images in to proper black and white form (almost). and so the recognition is better for all images 🙂

Need help with proper binarization of images. Any Idea will be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:27:51+00:00Added an answer on June 13, 2026 at 11:27 pm

    Hi all Thanks for your replies, from all of that replies I am able to get this conclusion as below:

    1. I need to get the only one cropped image block with number plate contained in it.
    2. From that plate need to find out the portion of the number portion using the data I got using the method provided here.
    3. Then converting the image data to almost black and white using the RGB data found through the above method.
    4. Then the data is converted to the Image using the method provided here.

    Above 4 steps are combined in to one method like this as below :

    -(void)getRGBAsFromImage:(UIImage*)image
    {
        NSInteger count = (image.size.width * image.size.height);
        // First get the image into your data buffer
        CGImageRef imageRef = [image CGImage];
        NSUInteger width = CGImageGetWidth(imageRef);
        NSUInteger height = CGImageGetHeight(imageRef);
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
        NSUInteger bytesPerPixel = 4;
        NSUInteger bytesPerRow = bytesPerPixel * width;
        NSUInteger bitsPerComponent = 8;
        CGContextRef context = CGBitmapContextCreate(rawData, width, height,
                                                     bitsPerComponent, bytesPerRow, colorSpace,
                                                     kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
        CGColorSpaceRelease(colorSpace);
    
        CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
        CGContextRelease(context);
    
        // Now your rawData contains the image data in the RGBA8888 pixel format.
        int byteIndex = 0;
        for (int ii = 0 ; ii < count ; ++ii)
        {
            CGFloat red   = (rawData[byteIndex]     * 1.0) ;
            CGFloat green = (rawData[byteIndex + 1] * 1.0) ;
            CGFloat blue  = (rawData[byteIndex + 2] * 1.0) ;
            CGFloat alpha = (rawData[byteIndex + 3] * 1.0) ;
    
            NSLog(@"red %f \t green %f \t blue %f \t alpha %f rawData [%d] %d",red,green,blue,alpha,ii,rawData[ii]);
            if(red > Required_Value_of_red || green > Required_Value_of_green || blue > Required_Value_of_blue)//all values are between 0 to 255
            {
                red = 255.0;
                green = 255.0;
                blue = 255.0;
                alpha = 255.0;
                // all value set to 255 to get white background.
            }
            rawData[byteIndex] = red;
            rawData[byteIndex + 1] = green;
            rawData[byteIndex + 2] = blue;
            rawData[byteIndex + 3] = alpha;
    
            byteIndex += 4;
        }
    
        colorSpace = CGColorSpaceCreateDeviceRGB();
        CGContextRef bitmapContext = CGBitmapContextCreate(
                                                           rawData,
                                                           width,
                                                           height,
                                                           8, // bitsPerComponent
                                                           4*width, // bytesPerRow
                                                           colorSpace,
                                                           kCGImageAlphaNoneSkipLast);
    
        CFRelease(colorSpace);
    
        CGImageRef cgImage = CGBitmapContextCreateImage(bitmapContext);
    
        UIImage *img = [UIImage imageWithCGImage:cgImage];
    
        //use the img for further use of ocr
    
        free(rawData);
    }
    

    Note:

    The only drawback of this method is the time consumed and the RGB value to convert to white and other to black.

    UPDATE :

        CGImageRef imageRef = [plate CGImage];
        CIContext *context = [CIContext contextWithOptions:nil]; // 1
        CIImage *ciImage = [CIImage imageWithCGImage:imageRef]; // 2
        CIFilter *filter = [CIFilter filterWithName:@"CIColorMonochrome" keysAndValues:@"inputImage", ciImage, @"inputColor", [CIColor colorWithRed:1.f green:1.f blue:1.f alpha:1.0f], @"inputIntensity", [NSNumber numberWithFloat:1.f], nil]; // 3
        CIImage *ciResult = [filter valueForKey:kCIOutputImageKey]; // 4
        CGImageRef cgImage = [context createCGImage:ciResult fromRect:[ciResult extent]];
        UIImage *img = [UIImage imageWithCGImage:cgImage]; 
    

    Just replace the above method’s(getRGBAsFromImage:) code with this one and the result is same but the time taken is just 0.1 to 0.3 second only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay..so before you mark this is as a repeated question, read it. I've implemented
Please do tell me what does an exclamation mark mean before a NSString NSString
Just as in the title, what does an exclamation mark before a function really
Possible Duplicate: What does the exclamation mark do before the function? What's the point
before I start I want to point out that I tagged this question as
Before asking the question let me preface with the fact that I am new
Before asking my question, let me explain the context. CONTEXT: I have a web
(Before I start, yes I have asked a similar question before; unfortunately due to
Before starting, I'm not asking about standard coding practice or etiquette. My question is
Before I ask my question, I want to mention that I am only today

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.