Results 1 to 23 of 23

Thread: Complicated Bitmap finding.

  1. #1
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default Complicated Bitmap finding.

    Heya =).

    Im currently working on a ways to always detect the "Letter" in that image:


    And i want to use it to detect the whole alphabet with alternating backgrounds(A to Z)...


    First I tried:
    "FindBitmapMaskTolerance". I made a Nice Mask, and it worked quite Well.

    The Problem:
    The Mask for L Looks Like this: " | ".
    Means That it Will also detect Letters Like "N, D, B...." (Everything that has a Long line).

    Then i tried:
    "FindTransparentBitmapTolerance".

    I got an image from the letter, im searchig for:


    The Problem is visible in the Image.

    AntiAliasing! ( The edges of the letter mix with the background color ), that makes it very hard to detect the letter with a changed background.

    I need to turn the tolerance higher than 100, to detect the Letter. But when the Tolerance is that high, it begins to detect wrong letters too.


    Please help me out : D.

    ~caused

  2. #2
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I would try a DTM of the black lettering. Then it doesn't matter what the background is. Just make a DTM array for every letter (making sure you select enough points so 2 letters don't get confused) and then do like:

    SCAR Code:
    var TheLetter: Integer;
    for i := 1 to 26 do
      if(FindDTM(DTMArray[i],x,y))then
        TheLetter := i;

    Let me know if you need any help with DTM's if you don't know them already.
    Last edited by JAD; 07-04-2009 at 01:17 AM.

  3. #3
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    DTMS, Countcolor, GetTPABounds?
    All of those are good alternatives.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  4. #4
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Could you post a link to the captcha or a PNG of one?

  5. #5
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Dtms are no option. I think x 'D....

    I'll show you why. This is the Letter "L":


    The DTM Finds:


    And When i raise the tolerance to 100+(to detect the whole L), its the same problem as with FindTransparentBitmapTolerance. It detects much more than the L...

    Also... The Letter E, also contains an L... So L will detect E ... geez. i dont know any further ...

  6. #6
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Use CountColor..

  7. #7
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Use CountColor..
    How ?.

    Remember, i might have a full alphabet or more to scan... Not just one single letter.

    If I'd use countcolors i'd need a way to detect the location of the Letter. And a box around the letter.

    ~caused.

  8. #8
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Get the max Length/width of all of the letter, and
    use something like

    FindColorsSpiralTolerance(..);
    ATPA := TPAToATPAEx(wid, hight);

    Then count the amount of black within the ATPA.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  9. #9
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I wrote something that I think will help you, but I need a lossless image of the captcha if you have one..

    Also I think that he means that you need to find the letter with a bitmap and then verify it with a CountColor.

  10. #10
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    @noidea:
    What if 2 Letters Have the same amount of (black) pixels ?

  11. #11
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    DTM's would work with the letter A's you posted at least. I don't understand how DTM's wouldn't be the best solution? Take a DTM of one of the A's, and searching for it will result true for any of those A's there.

  12. #12
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    I wrote something that I think will help you, but I need a lossless image of the captcha if you have one..

    Also I think that he means that you need to find the letter with a bitmap and then verify it with a CountColor.
    Heres a difficult one:


    Oh.. i was just too lazy to Create different letters, so i turned the A's around.. Lets pretend theyre different letters


    @JAD: Im quoting myself
    Also... The Letter E, also contains an L... So L will detect E ... geez. i dont know any further ...

    Edit2:
    Oh. For those who didnt got the problem yet: I Think its the anti aliasing and also the very small size of the Letters. Heres an example, how AntiAliasing makes it hard to detect the letter:



    Now Remember, when the background color changes, the whole part of "different color here" changes as well.

    ~caused
    Last edited by caused; 07-04-2009 at 01:54 AM.

  13. #13
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    My original idea didn't work too well, but I came up with this:
    SCAR Code:
    procedure FixCaptcha(BMP: Integer);
    var
      x, y, W, H: Integer;
      Hue, S, L: Extended;
    begin
      GetBitmapSize(BMP, W, H);
      for y:= 0 to H - 1 do
      begin
        for x:= 0 to W - 1 do
        begin
          ColortoHSL(FastGetPixel(BMP, x, y), Hue, S, L); //convert the current pixel to HSL
          if(L < 60)then //if the luminance of that pixel is less than 60, then...
            FastSetPixel(BMP, x, y, 0) //make it black
          else //otherwise..
            FastSetPixel(BMP, x, y, clWhite); //make it white
        end;
      end;
    end;
    It's very simple, but it works pretty well to retrieve just the letters. It's definitely not perfect, so play around with the "L < 60" and maybe add saturation checking too to get it just how you want it.
    Last edited by bullzeye95; 07-04-2009 at 03:39 AM.

  14. #14
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Hey, thanks.
    Could you please comment it a bit ?.

    What does it exactly do ?

    It looks like it just alters the bmp. Though, i dont see how this could help me :/.

    Wouldnt i have the same problems as i stated above ?. That i cant set a Tolerance, that just finds the Letter I want.

    ~caused

  15. #15
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I commented it as well as I could (and edited it, because I kept two unnecessary lines in it). You are right, it will just alter the bitmap, getting rid of the anti-aliasing. If that was not a problem, then sorry. If it was a problem, now you won't have to use any tolerance at all.
    You could:
    1. Use my procedure to monochrome the bitmap
    2. Loop through the alphabet, searching for a bitmap of each letter (possibly use deformed bitmap finding)
    3. Check the location of each found letter with CountColors to make sure, for example, an L is not really an E
    4. Sort the found letters by their x location

  16. #16
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Well. that sounds all good and stuff.. buuut xD..

    When i got those no AntiAliasing Bmp's all ready, the image i'm searching on, wont have the same letters, as in the altered bmp's. So a BMP search would only deliver results, if i used a very high tolerace, which brings me back to my old problem..

    ~caused

  17. #17
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Use bitmap masking... And for the bitmap rotation just look at the srl function for finding bitmaps rotated



    ~NS

  18. #18
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by Nadeem View Post
    Use bitmap masking... And for the bitmap rotation just look at the srl function for finding bitmaps rotated



    ~NS
    That was the first thing i tried

    First I tried:
    "FindBitmapMaskTolerance". I made a Nice Mask, and it worked quite Well.

    The Problem:
    The Mask for L Looks Like this: " | ".
    Means That it Will also detect Letters Like "N, D, B...." (Everything that has a Long line).

    Im working on another method though....

  19. #19
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    SCAR Code:
    program New;
    {.include srl/srl.scar}

    //This works with Notepad on
    //'Font = Arial Black, Font style = Regular, Size = 14'


    Function LetterLibrary(Count: Integer): String;
    begin
      Case Count of
        84: Result := 'A';
        119: Result := 'B';
        78: Result := 'C';//F aswell =\
        100: Result := 'D';
        105: Result := 'E';
        96: Result := 'G';//Q
        102: Result := 'H';
        58: Result := 'J';
        103: Result := 'K';
        63: Result := 'L';
        106: Result := 'M';
        110: Result := 'N';
        88: Result := 'O';
        87: Result := 'P';
        96: Result := 'Q';//G
        109: Result := 'R';
        89: Result := 'S';
        58: Result := 'T';
        90: Result := 'U';
        70: Result := 'V';
        113: Result := 'W';//113/4
        87: Result := 'X';
        64: Result := 'Y';
        97: Result := 'Z';
      end;
    end;



    Function Analyze: String;
    var
      TPA: TPointArray;
      ATPA: Array of TPointArray;
      x, y, i: Integer;
    begin
      FindColorsTolerance(TPA, 0, 0, 0, 115, 60, 0);
      ATPA := TPAToATPAEx(TPA, 15, 16);

      For I := 0 to high(ATPA) do
        Result := Result + LetterLibrary(Length(ATPA[i]));//writeln('Pix['+inttostr(i)+'] = '+inttostr(Length(ATPA[i])));

      writeln('Num of Letters = '+inttostr(length(atpa)));
    end;




    begin
      setupsrl;
      writeln(Analyze);
    end.

    You could do something like this?
    This one doesnt work very well though
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  20. #20
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  21. #21
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    MouseBox does not help at all..

  22. #22
    Join Date
    Oct 2006
    Location
    Ontario,Canada
    Posts
    1,718
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    could you not use. findcolorstolerance -> LoadTextTPA -> FindTextTPAinTPA?

  23. #23
    Join Date
    May 2009
    Posts
    799
    Mentioned
    2 Post(s)
    Quoted
    16 Post(s)

    Default

    Quote Originally Posted by XcanadamanX View Post
    could you not use. findcolorstolerance -> LoadTextTPA -> FindTextTPAinTPA?
    Actually, that sounds good. Though, i cant figure out how to use "LoadTextTPA"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •