Image Recognition? VB 2010

Discussion in 'Programming General' started by master414, Apr 12, 2012.

Image Recognition? VB 2010
  1. Unread #1 - Apr 12, 2012 at 3:44 PM
  2. master414
    Joined:
    Feb 26, 2006
    Posts:
    214
    Referrals:
    0
    Sythe Gold:
    0

    master414 Active Member

    Image Recognition? VB 2010

    How do I make it so it detects any image on your screen, and finds the XY coordinates of it, then clicks on it?

    Anyone have a video tutorial or source? I would even pay learning how this is done.


    Edit: As an extra, how do you make hotkeys triggering a macro? So if I press Y for example, it'll press the following keys: A, B, C, F1, F2, ESC.
     
  3. Unread #2 - Apr 14, 2012 at 6:41 AM
  4. master414
    Joined:
    Feb 26, 2006
    Posts:
    214
    Referrals:
    0
    Sythe Gold:
    0

    master414 Active Member

    Image Recognition? VB 2010

    Is it that difficult? I am willing to pay much $$$.
     
  5. Unread #3 - Apr 14, 2012 at 10:08 AM
  6. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Image Recognition? VB 2010

    I could make this program for you, but first i have to ask is it for a game or a webpage?
    If it's a game can you give me a printscreen of what you will be trying to click.

    As for the hotkeys look at the source in this thread:
    http://sythe.org/showthread.php?t=1228818

    There is also a colour clicker source there that may aid you into your image clicker as it uses the same principle.
     
  7. Unread #4 - May 21, 2012 at 6:39 PM
  8. _joewnn
    Joined:
    May 19, 2012
    Posts:
    9
    Referrals:
    0
    Sythe Gold:
    0

    _joewnn Newcomer
    Banned

    Image Recognition? VB 2010

    Here is some code in Delphi, can't remember if I wrote it or not, but it was in one of my old macro projects. Cruel may have written it, or a similar function, so I;m really not sure if I can take credit. its been years since I opened this

    Code:
    function FindBitmapBox(wHandle: HWND; xs,ys,xe,ye:integer; bitmap: Integer; var x, y: Integer; flag, tol, mask: Integer): Boolean;
    var
      bmp1, bmp2: TBitmap;
      x1, y1, x2, y2, tmpColor, FirstColor: Integer;
      FirstPoint: TPoint;
      tmpDC: HDC;
      tmpRECT: TRect;
      p, p2, p3: PRGBArray;
    label first, done, testy;
    begin
      GetWindowRECT(wHandle, tmpRECT);
      //showmessage(inttostr(tmprect.top));
      tmpDC := getwindowdc(wHandle);
      bmp2 := TBitmap.Create;
      bmp2.Handle := bitmap;
      bmp1 := TBitmap.Create;
      bmp1.PixelFormat := pf24bit;
      bmp1.Width := tmpRECT.Right - tmpRECT.Left;
      bmp1.Height := tmpRECT.Bottom - tmpRECT.Top;
      BitBlt(bmp1.Canvas.Handle, 0, 0, xe - xs, ye - ys, tmpdc, xs, ys, SRCCOPY);
      //BitBlt(form1.image2.Canvas.Handle, 0, 0, xe - xs, ye - ys, bmp1.canvas.handle, 0, 0, SRCCOPY);
      bmp1.Height := ye - ys;
      bmp1.Width := xe - xs;
      releasedc(whandle,tmpDC);
      Result := True;
      FirstPoint.X := 0; FirstPoint.Y := 0;
    
      if mask >= 0 then begin
        for y1 := 0 to bmp2.Height - 1 do
          for x1 := 0 to bmp2.Width - 1 do
            if GetPixel(bmp2.Canvas.Handle, x1, y1) <> mask then begin
              FirstColor := GetPixel(bmp2.Canvas.Handle, x1, y1);
              FirstPoint.X := x1; FirstPoint.Y := y1;
              goto first;
            end;
        x := round(bmp2.Width / 2);
        y := round(bmp2.Height / 2);
        goto done;
      end;
      FirstColor := GetPixel(bmp2.Canvas.Handle, 0, 0);
      first:
     //showmessage(inttostr(FirstPoint.x));
      for y1 := 0 to bmp1.Height - 1 do begin
        p := bmp1.ScanLine[y1];
        for x1 := 0 to bmp1.Width - 1 do begin
          tmpColor := RGB(p[x1].b, p[x1].g, p[x1].r);
          if SimilarColors(tmpColor, FirstColor, tol) then begin
            for y2 := 0 to bmp2.Height - 1 do begin
              if y1 + y2 - FirstPoint.y > bmp1.height - 1 then goto testy;
              if y1 + y2 - FirstPoint.y < 0 then goto testy;
              p2 := bmp2.ScanLine[y2];
              p3 := bmp1.ScanLine[y1 + y2 - FirstPoint.y];
              for x2 := 0 to bmp2.Width - 1 do begin
                x := x1 + x2 - FirstPoint.X;
                tmpColor := RGB(p2[x2].b, p2[x2].g, p2[x2].r);
                if x > bmp1.Width - 1 then  goto testy;
                if x < 0 then goto testy;
                if mask < 0 then begin
                  if not SimilarColors(tmpColor, RGB(p3[x].b, p3[x].g, p3[x].r), Tol) then goto testy;
                end else if tmpColor <> mask then if not SimilarColors(RGB(p3[x].b, p3[x].g, p3[x].r), tmpColor, Tol) then goto testy;
              end;
            end;
            //showmessage(inttostr(x1-firstpoint.X)+','+inttostr(y1-firstpoint.Y));
            x := xs + x1 - FirstPoint.x; y := ys  + y1 - FirstPoint.Y;
            if flag in [4, 5, 6] then y := y + ys + round(bmp2.Height / 2);
            if flag in [7, 8, 9] then y := y + ys + bmp2.Height;
            if flag in [2, 5, 8] then x := x + xs + round(bmp2.Width / 2);
            if flag in [3, 6, 9] then x := x + xs + bmp2.Width;
            goto done;
          end;
          testy:
        end;
      end;
    
      Result := False;
      done:
      bmp1.Free;
      bmp1 := nil;
      bmp2.ReleaseHandle;
      bmp2.Free;
      bmp2 := nil;
    end;


    Obviously you're going to have to translate some code, but it should be fairly easy considering how similar Delphi 7 and VB6 are. There is no scanline property in VB, so if you have any difficulties let me know and I can help.

    and hey covey ;)
     
  9. Unread #5 - May 21, 2012 at 6:46 PM
  10. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    Image Recognition? VB 2010

    Oh hullo joewnn :3 You should make a high pardon so you can come back and I don't have to ban you all the time
     
< Anyone know eclipse | [VB.NET][TUT] Winforms Desktop Numerical Clock "Gadget" >

Users viewing this thread
1 guest


 
 
Adblock breaks this site