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 7519603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:55:55+00:00 2026-05-30T01:55:55+00:00

I’ve managed to do recognize characters from image. For this reason: I save all

  • 0

I’ve managed to do recognize characters from image. For this reason:

I save all recognized blobs(images) in List

        Bitmap bpt1 = new Bitmap(@"C:\2\torec1.png", true);
        Bitmap bpt2 = new Bitmap(@"C:\2\torec2.png", true);
        List<Bitmap> toRecognize = new List<Bitmap>();
        toRecognize.Add(bpt1);
        toRecognize.Add(bpt2);

I keep a library of known letters in Dictionary.

            Bitmap le = new Bitmap(@"C:\2\e.png", true);
            Bitmap lg = new Bitmap(@"C:\2\g.png", true);
            Bitmap ln = new Bitmap(@"C:\2\n.png", true);
            Bitmap li = new Bitmap(@"C:\2\i.png", true);
            Bitmap ls = new Bitmap(@"C:\2\s.png", true);
            Bitmap lt = new Bitmap(@"C:\2\t.png", true);
            var dict = new Dictionary<string, Bitmap>();
            dict.Add("e", le);
            dict.Add("g", lg);
            dict.Add("n", ln);
            dict.Add("i", li);
            dict.Add("s", ls);
            dict.Add("t", lt);

Then I create New List with Images – from library:

var target = dict.ToList();

And do the comparison of images: (target[index].Key, target[index].Value)

for (int i = 0; i < x; i++)
{
   for (int j = 0; j < y; j++)
   {
       if (CompareMemCmp(toRecognize[i], target[j].Value) == true)
       {
       textBox3.AppendText("Found!" + Environment.NewLine);
       textBox2.AppendText(target[j].Key); //Letter is found - save it!
       }
       else {textBox3.AppendText("Don't match!" + Environment.NewLine); }
   }
}

1. [removed]

2. Is the method that I used tolerable from the perspective of performance? I’m planning to do the recornition of 10-20 images at the same time (average letter count for each is 8) and the library for letters will consist of English alphabet (26 upper + 26 lower case), special letter(~10) and Numbers (10).

So I have 80+ letters that have to be recognized and pattern library which consists of ~70+ characters. Will the performance be at a good level?

Constructive criticism gladly accepted. 😉

  • 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-05-30T01:55:55+00:00Added an answer on May 30, 2026 at 1:55 am

    Question 1:

    [removed]

    Question 2:

    It depends.
    First of all, if performance is not enough, what’s your bottleneck ?
    I suspect it’s CompareMemCmp() function… so can you speed-up it ?

    If not, given that each iteration of your loop seems independent from the previous ones, you could try to run it in parallel.
    To do this have a look at the Task Parallel Library methods of framework 4.0, in particular to Parallel.For.

    EDIT :

    If we are talking about perfect matching between images, you can try to use dictionary look-up to speed things up.

    First, you can build a wrapper class for Bitmap that can be efficiently used as Dictionary<> key, like this:

    class BitmapWrapper
    {
        private readonly int hash;
        public Bitmap Image { get; private set; }
        public BitmapWrapper(Bitmap img)
        {
            this.Image = img;
            this.hash = this.ComputeHash();
        }
    
        private int ComputeHash()
        {
            // you could turn this code into something unsafe to speed-up GetPixel
            // e.g. using lockbits etc...
            unchecked // Overflow is fine, just wrap
            {
                int h = 17;
                for (int x = 0; x < this.Image.Size.Width; x++)
                    for (int y = 0; y < this.Image.Size.Height; y++)
                        h = h * 23 + this.Image.GetPixel(x, y).GetHashCode();
                return h;
            }
        }
    
        public override int GetHashCode()
        {
            return this.hash;
        }
        public override bool Equals(object obj)
        {
            var objBitmap = obj as Bitmap;
            if (obj == null)
                return false;
            // use CompareMemCmp in case of hash collisions 
            return Utils.CompareMemCmp(this.Image, objBitmap); 
        }
    }
    

    This class computes the hascode in ComputeHash method that is inspired by this answer (but you can just ex-or every pixel). That surely can be improved by involving unsafe code (something like in the CompareMemCmp method).

    Once you have this class, you can build a look-up dictionary like this:

    Bitmap le = new Bitmap(@"C:\2\e.png", true);
    Bitmap lg = new Bitmap(@"C:\2\g.png", true);
    ...
    var lookup = new Dictionary<string, Bitmap>();
    lookup.Add(new BitmapWrapper(le), "e");
    lookup.Add(new BitmapWrapper(lg), "g");
    ...
    

    then the search will be simply:

    foreach(var imgToRecognize in toRecognize)
    {
       string letterFound;
       if(lookup.TryGetValue(new BitmapWrapper(imgToRecognize), out letterFound))
       {
          textBox3.AppendText("Found!" + Environment.NewLine);
          textBox2.AppendText(letterFound); //Letter is found - save it!
       }
       else
          textBox3.AppendText("Don't match!" + Environment.NewLine);
    }
    

    The performances of this method definitely depends on the hash computation, but certainly they can save a lot of CompareMemCmp() calls.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

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.