Solved

Locate position of letters in a image

Posted on 2008-10-29
24
209 Views
Last Modified: 2013-11-22
How can I locate the position of two letters in a image ?

Ex: PO or 01 or SE or PN.

Do I really need a OCR software to accomplish this?

Regards,

-B
0
Comment
Question by:MrSimpson
  • 11
  • 10
  • 3
24 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22834867
>Do I really need a OCR software to accomplish this?
I'm afraid so.  It's either that, or write your own equivalent of OCR.
0
 

Author Comment

by:MrSimpson
ID: 22835138
If II'm looking for the letters CE, would it be impossible
to "locate" them using scanline or something?
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835251
>> to "locate" them using scanline or something?

if you know for about 98% how that CE looks like on the image, then no. but if it can have any font size, and font type and any position and distance between characters, then it's impossible without an OCR.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 22835270
ScanLine returns a PByteArray. This array of bytes does not contain any valid charaters. It only contains bytes that represent a color shown in a given pixel. There are no characters to be located there. The only way to this is through some form of pattern matching (OCR). Even the very good stuff is not %100 accurate.
0
 

Author Comment

by:MrSimpson
ID: 22835290
It will be in the same position always, same font.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 22835340
Will colors be exactly the same as well?
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835348
>> It will be in the same position always, same font.

then all you need to do is to create a small file which will contain the exact pixels for the 2 characters and when you read in teh bitmap, you will check for this pixels on it. liek

000100000
000100000
000100000
000100000
000100000
000100000
000111110
000000000

this represents where on the bitmap is the letter L. if 0, nothing, if it's 1, it means that there should be the pixel.

now, since you know everything about it, all you need to check is that all pixels with value 1 have the same color AND, all pixels with value 0 which are near a 1 do not hae the same value as the pixels with value 1.

are you able to do this by yourself? I don't have time tonight to make you a demo. maybe in the following days. this is not a 20 minutes demo, it will take quite some time.
0
 

Author Comment

by:MrSimpson
ID: 22835386
Let's say the PixelFormat := pf1bit;
The PByteArray would have a 0 byte for a "black" byte and a 255 for a white byte.
If I created a array (640 x 480) and set the white bytes to 0 and the black bytes to X.
Would'nt it be possible to recognize the X's as a character L?
Like:
0000x00000
0000x00000
0000xxx000
0000000000

Huh?
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835407
that is basic OCR :)
0
 

Author Comment

by:MrSimpson
ID: 22835410
ciuly: You read my mind!!!!
0
 

Author Comment

by:MrSimpson
ID: 22835415
scary!
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835443
>> ciuly: You read my mind!!!!

not really. what you are suggesting is OCR, recognizing some pixels a specific character. what I am saying is matching a set of pixels to another set, which you know what stands for. there are similarities, but your suggestion is generic, and hence OCR, where as mine is concentrated on pre-generated stuff. very limited, but seems to be ok for your scenario.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:MrSimpson
ID: 22835500
We used the same letter 'L' in the sample too!  :O)
Don't need to check the value of the color if I use PixelFormat := pf1bit;
 
0
 

Author Comment

by:MrSimpson
ID: 22835563
got this so far,,,

  bmp := TBitmap.Create;
  bmp.LoadFromFile('c:\test.bmp');
  bmp.PixelFormat := pf1bit;
  for y := 0 to bmp.Height -1 do
  begin
    Row := bmp.ScanLine[y];
    for x := 0 to bmp.Width -1 do //Image2.Width do
    begin
      // Code ,,,
    end;
  end;
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835574
>> We used the same letter 'L' in the sample too!

didn't notice that. lol.

>> PixelFormat := pf1bit;

that is correct. but if you initial bitmap has anotehr pixel format, then yuo will loose information and tat can make you read up false positives. imagine the letters being on a darkish area. the entire ara will become black. you won't see the letters.

OR, there will be some darkish areas that together will result in an aproximation of the letter, but it will not be the letter.

so if you were thinking to force a 1 bit perr pixel format, don't, unless you know for sure that you don't screw up things.
0
 

Author Comment

by:MrSimpson
ID: 22835667
>>unless you know for sure that you don't screw up things.
I usally do... :O)

Think I need to add a % of hit if you know what I mean.
Is it difficult? How do I do that?

0
 
LVL 28

Expert Comment

by:ciuly
ID: 22835893
>> Think I need to add a % of hit if you know what I mean.

I don't :)
0
 

Author Comment

by:MrSimpson
ID: 22835935
If not all X's are there  to make an L I should be able to approve it as a match.
If one x or a few more is missing it will be okay as long as it is 90% match.

Like:
XXX
XXX
XX0
XXX
0XXXXXXX0
XXXXXXXXX

Que? :O)
0
 

Author Comment

by:MrSimpson
ID: 22836122
Any suggestion on how to compare X's in a array with x's in the image?
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22836129
oh. you mean like % of accuracy :P of course you need it. but you will need to carefully think that percentage to be character specific, and even more, to be divided per zones.

example:

XXX
XXX
XX0
0XXx
0XXXX0
XXXXXx

is that a bad L or a bad I ? :)

so applying 1 percentage to all alphabet is not good enough.
but, you said that the letters will be in the same palce, same size, same font. that means that you can up that percentage to say 99%. that way you can have only one percantage without raising false negatives/positives.
0
 
LVL 28

Accepted Solution

by:
ciuly earned 500 total points
ID: 22836141
>> Any suggestion on how to compare X's in a array with x's in the image?

firstly, you need to decide how you array is positioned in the image. after that, you scanline through the image until you reach the array, then scanline thourgh the image and compare the X position from the scnaed line with the x position in the array. and as I already suggested, yuo also copmare the 0-es that are near x-es to be of different color.
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22836142
note: I'm off to bed now.
0
 

Author Closing Comment

by:MrSimpson
ID: 31511353
Thank you very much!
0
 
LVL 28

Expert Comment

by:ciuly
ID: 22838962
>> Thank you very much!

you're welcome
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In a previously published article (http://www.experts-exchange.com/articles/10331/Automatic-Duplex-Scanning-in-PaperPort-Versions-11-12-14.html) here at Experts Exchange, I explained how to achieve duplex (double-sided) scanning in Nuance's PaperPor…
This video is the second in a two-part series that discusses PaperPort's "Send To Bar" feature . The first video tutorial (http://www.experts-exchange.com/VP_207.html) explains the purpose of the Send To Bar, how to use it, and how to hide unwanted …
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now