Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31
Like Tree1Likes

Thread: Color/Image Recognistion in vbnet?

  1. #1
    Junior Member
    ownlikeaboss is offline

    Posts
    20

    Color/Image Recognistion in vbnet?

    Does this exist? I searched the internet and tried a few codes but nothing worked. The reason i use vb.net is because i see it at school and
    will be easier to program in for me except for the color/image finding, if anybody has a solution or code pls tell me thanks a lot!

  2. #2
    Bot Coder
    Severn is offline

    Posts
    104
    Okay, looking up image recognition will be misleading. You'll probably end up with a load of projects for image to text conversion or something :P You will have to make your own functions to do what you want. I can put you in the right direction though... Have a look at taking screenshots with VB.Net and storing them in bitmaps, then using the GetPixel() function to see what the colour of the pixel is at certain points. Using that and making you own algorithm to look and compare different pixels you should be able to make image detection for anything in theory If its for Puzzle Pirates it shouldn't be too hard because its only 2D Let me know if you need any help

  3. #3
    Junior Member
    ownlikeaboss is offline

    Posts
    20
    Well i've read that, so i should make a function which if the first pixel matches it checks for the second one etc. of the second image one on the first image.
    Ps do you code in vb net for bots?

    Can puzzle pirates detect if there is no mouse movement ?
    (scarecrow i'l add it to my previous post, this is just show there is a new post to severn)
    Last edited by ownlikeaboss; 08-12-2012 at 05:59 PM.

  4. #4
    Bot Coder
    Severn is offline

    Posts
    104
    What are you trying to do? Find if a certain reference image is on your screen? If so, the only real way to do it would be to cycle through each pixel, and when it finds a match for the first pixel, it will continue to loop through the rest until it either finds a difference or completely finds the reference image. To make it efficient you would need to place while loops inside other while loops.

    Yep, I love VB.Net! It has no real advantages over C hash or C++ in terms of efficiency if you code it right, but its really simple to write! :P

  5. #5
    Junior Member
    ownlikeaboss is offline

    Posts
    20
    Well i take a screenshot and then try to find the login/puzzles/pieces/buttons on it of puzzle pirates.

  6. #6
    Bot Coder
    Severn is offline

    Posts
    104
    Okay, with Puzzle Pirates theres a nice little trick you can do. Since you know where everything on the screen is going to be when its set to a certain resolution (800x600 say, like all the bots use) you can know where everything is going to be in the window. This means that if you find the position of the window on the screen, you can just take a screenshot of that part of the screen. Then you'll have a bitmap of just the Puzzle Pirates graphics instead of the whole screen, and you don't have to go searching with reference images. For example, if you know the Puzzle Pirates window is 100 pixels from the left of the screen and 150 from the top, you can take a screenshot of the screen starting at 100,150 and have it 800 wide and 600 high. And then you can direct your program to look at the bitmap you have got and you can scan single reference pixels to tell what state the game is in. So if you wanted to know if the game was in.. say the sword fighting puzzle, you'd say "Oh, I know what colour one of the pixels of the sword fighting background, so if its the same as my screenshot then the game is sword fighting!"

    This way would be better then searching your whole screen for a reference image as well.

    To find the co ordinates of the window, you'll want to look into window handles. You can find the WHID (window handle ID) from a window title, so you can search for a window with the name "Puzzle Pirates - * on the * ocean" (where * is a wildcard symbol) and the use that window handle to find the position of the screen.

    Google is your friend

  7. #7
    Junior Member
    ownlikeaboss is offline

    Posts
    20
    Fuck im getting error arithmetic operation overflow.

  8. #8
    Bot Coder
    Severn is offline

    Posts
    104
    That means that you have overflowed on your data type. Which means the number you have gotten form one of your operations results in a number too big to fit into this data type.

  9. #9
    Junior Member
    ownlikeaboss is offline

    Posts
    20
    I know but i tried the codes that i found and i can't get any to work and i think i'm really close with this one.

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


    Public Function WindowHandle(ByVal sTitle As String) As Long

    WindowHandle = FindWindow(vbNullString, sTitle)

    End Function


    Private Sub FindWindowPuzzlePirates()

    Dim windowname As String = "Puzzle Pirates"

    Dim ParenthWnd As New IntPtr(0)

    ParenthWnd = WindowHandle(windowname) (error)

    Dim theprogramrectangle As System.Drawing.Rectangle

    GetWindowRect(ParenthWnd, theprogramrectangle)

    strWindowX = theprogramrectangle.X

    strWindowY = theprogramrectangle.Y

    End Sub

  10. #10
    Bot Coder
    Severn is offline

    Posts
    104
    Okay, instead of finding a window handle using the FindWindow function, retrieve the the whID of the active window, then use it it to check if the title of the window is right. Also when checking the title, don't do:

    If WindowName = "Puzzle Pirates" Then
    But instead try:

    If WindowName Like "Puzzle Pirates*" Then
    Because when the client logs in the title changes to 'Puzzle Pirates - Username on the Emerald ocean' instead, and the second one will account for that.

    The reason this is a better way of doing is because; firstly you check to see if Puzzle Pirates is the active window, secondly you don't need to worry about multiple instances of the client, which your example won't take into consideration and thirdly you don't need to worry if an instance of the client isn't open.

    Granted neither of these methods account for whether its actually the game client, they just check the title. This means using this method its possible to trick your program into thinking its the Puzzle Pirates window by just giving it the right name, but theres no real harm in this because nobody would want to exploit this. :P

    To find the active window look into the GetActiveWindow function, and then all you need to do is whack it into what you have already.

    That should be all the info you need Just call if you need a hand


    Edit: Sorry I forgot to say... to get the window name from the handle you'll also need to look into GetWindowText, but thats simple enough

Page 1 of 4 123 ... LastLast

Posting Permissions

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