Announcement

Collapse
No announcement yet.

Color/Image Recognistion in vbnet?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    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

    Comment


      #3
      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, 04:59 PM.

      Comment


        #4
        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

        Comment


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

          Comment


            #6
            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

            Comment


              #7
              Fuck im getting error arithmetic operation overflow.

              Comment


                #8
                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.

                Comment


                  #9
                  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

                  Comment


                    #10
                    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

                    Comment


                      #11
                      So i don't need to use findwindow?

                      Comment


                        #12
                        Nope, not at all :P

                        Comment


                          #13
                          Can i use anything of the code i posted?

                          I should start over?

                          Are you sure i don't need to use findwindow? I get it in like every code i search for. Maybe i'm lookiong wrong, my google keywords are 'how find window handle vb net by title'.

                          I have no clue on what i have to do now.

                          <DllImport("user32.dll", SetLastError:=True)> Private Shared Function GetForegroundWindow() As IntPtr
                          End Function

                          Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer) As Integer

                          Private Sub FindWindowPuzzlePirates()

                          Dim lngPid As Integer

                          GetWindowThreadProcessId(GetForegroundWindow, lngPid)




                          End Sub
                          Nvm i think i got it

                          I can't get it to confirm if it's the puzzle pirate window

                          What i mean is that i can't get the title.

                          I can't get the title to show up.
                          Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

                          FindWindowPuzzlePirates()
                          Label1.Text = lngPid.ToString

                          length = GetWindowTextLength(GetForegroundWindow)

                          Dim sb As New System.Text.StringBuilder("", length + 1)

                          GetWindowText(GetForegroundWindow, sb, sb.Capacity)

                          If sb.ToString Like "Puzzle Pirates" Then
                          MessageBox.Show("test")
                          End If

                          MessageBox.Show(sb.ToString)

                          End Sub
                          Last edited by Scarecrow; 08-12-2012, 07:22 AM. Reason: Like a billion double posting

                          Comment


                            #14
                            for your FindWindowPuzzlePirates() you should be using GetForegroundWindow() :P you can... i'll just write the code for you, i'm in a good mood

                            Note: it's late for me.. this could have a million errors and have me not notice, but hey :P

                            First set up a timer, call it Timer1 if its not already named that, set the interval to 1 (which is 1ms) and enable it.
                            Secondly a Label called Label1

                            Then here is your code +/- a few mistakes :P



                            Structure RECT
                            Public Left As Integer
                            Public Top As Integer
                            Public Right As Integer
                            Public Bottom As Integer
                            End Structure

                            Public Declare Function GetForegroundWindow Lib "user32" () As Long

                            Public Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal prmstrString As String, ByVal nMaxCount As Long) As Long

                            Public Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As Long, prmtypRECT As RECT) As Long

                            Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
                            Dim ForeGroundhwID As Long = GetForegroundWindow()
                            Dim ForeGroundText As String

                            If ForeGroundhwID <> 0 Then
                            ForeGroundText = GetText(ForeGroundhwID)
                            End If

                            If ForeGroundText Like "Puzzle Pirates*" Then
                            Dim PuzzlePiratesRect As Rect
                            Dim BorderWidth, X, Y As Integer

                            GetWindowRect(ForeGroundhwID, PuzzlePiratesRect)

                            BorderWidth = (PuzzlePiratesRect.Right - PuzzlePiratesRect.Left - 800) / 2
                            X = PuzzlePiratesRect.Left + BorderWidth
                            Y = PuzzlePiratesRect.Bottom - BorderWidth - 600

                            Label1.Text = "Puzzle Pirates graphics at " & X & "," & Y
                            Else
                            Label1.Text = "Nothing Found"
                            End If
                            End Sub

                            Public Function GetText(ByVal hWnd As IntPtr) As String
                            Dim TextLength As Integer

                            TextLength = GetWindowTextLength(hWnd)

                            If length = 0 Then
                            Return Nothing
                            End If

                            Dim sb As New System.Text.StringBuilder("", TextLength + 1)

                            GetWindowText(hWnd, sb, sb.Capacity)

                            Return sb.ToString()
                            End Function
                            Oh yeah, while I was writing this I remembered something else... The FindWindowRect() function finds the co-ordinates foe the window, but it still has the border for the window added on, so I added in a little arithmatic to find the location of the graphics instead. It looks right to me, but I bet theres a typo somewhere... :S but still, you should be able to take that and now get a bitmap of the YPP! graphics by putting in the co-ordinates

                            Comment


                              #15
                              Don't double post, I've issued you with an infraction because you literally posted about 7 posts in a row. Please use the edit function ,

                              Thanks.
                              Last edited by Scarecrow; 08-12-2012, 07:38 AM.

                              Comment

                              Working...
                              X