Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Locate position of letters in a image

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
MrSimpson
Asked:
MrSimpson
  • 11
  • 10
  • 3
1 Solution
 
SteveBayCommented:
>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
 
MrSimpsonAuthor Commented:
If II'm looking for the letters CE, would it be impossible
to "locate" them using scanline or something?
0
 
2266180Commented:
>> 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SteveBayCommented:
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
 
MrSimpsonAuthor Commented:
It will be in the same position always, same font.
0
 
SteveBayCommented:
Will colors be exactly the same as well?
0
 
2266180Commented:
>> 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
 
MrSimpsonAuthor Commented:
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
 
2266180Commented:
that is basic OCR :)
0
 
MrSimpsonAuthor Commented:
ciuly: You read my mind!!!!
0
 
MrSimpsonAuthor Commented:
scary!
0
 
2266180Commented:
>> 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
 
MrSimpsonAuthor Commented:
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
 
MrSimpsonAuthor Commented:
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
 
2266180Commented:
>> 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
 
MrSimpsonAuthor Commented:
>>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
 
2266180Commented:
>> Think I need to add a % of hit if you know what I mean.

I don't :)
0
 
MrSimpsonAuthor Commented:
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
 
MrSimpsonAuthor Commented:
Any suggestion on how to compare X's in a array with x's in the image?
0
 
2266180Commented:
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
 
2266180Commented:
>> 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
 
2266180Commented:
note: I'm off to bed now.
0
 
MrSimpsonAuthor Commented:
Thank you very much!
0
 
2266180Commented:
>> Thank you very much!

you're welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 11
  • 10
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now