Results 1 to 15 of 15

Thread: compare images

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    22

    compare images

    hi all i got a question, i tried lots of things but i cant find any answers. how can i compare a picture in a picture box with something on the screen at given coordinates, im looking for something like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Public Sub CompareIMG()
    4. Dim intX As Integer
    5. Dim intY As Integer
    6.  
    7. Dim blnMatch As Boolean     'True if pictures match
    8.  
    9.     If intX > 200 Then      'Check within given coordinates
    10.         intX = 0
    11.         intY = intY + 1
    12.     Else
    13.         Do Until blnMatch = True
    14.             'Here is what i dont get, i hope it will be short like this:
    15.             Compare picImage With (intX, intY), blnMatch
    16.            
    17.             intX = intX + 1
    18.         Loop
    19.     End If
    20.        
    21. End Sub

    but it will probably will be very different
    I hope anyone knows how to do something like this

    Bye, Koen

  2. #2
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    This is an old project I made for comparing pictures.. I hope it helps you

    (I removed this old version of the PicComp Project, download the current one that is posted below.)
    Last edited by Tec-Nico; Aug 16th, 2004 at 09:44 AM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  3. #3
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Is it just me, or does that code only compare the size of the images?

  4. #4
    New Member
    Join Date
    Aug 2004
    Posts
    8
    If you have a good look at the code you will notice the comment "'Compare the Colors of Each Byte". This is the loop which compares the two images byte by byte, so no it's not just comparing file sizes

  5. #5
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    I see, but this still happens:
    Attached Images Attached Images  

  6. #6
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    And it's because the byte arrays are empty, the line to populate them fails:
    VB Code:
    1. Debug.Print GetBitmapBits(Pic1, bmHeight * bmWidthBytes, Bytes1(0, 0))
    Returns a 0.

  7. #7
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Sorry... I have two versions of the project and unfortunatelly I attached the oldest of them.

    Here is the real thing.
    Attached Files Attached Files
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    22
    thanks all for replys, i now have an idea how to do it but how can i compare an image with something on the screen, at given coordinates?

  9. #9
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Search the forums to see how to get a screenshot... So that might help you get the image in that point and then compare it.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    22
    i remember i could do something i wanted with colors, it made a spiral from the middle of the screen untill it finds the color. i was thinking of something sort like. i shall add a crappy bit of code, its very old from the time when i couldnt really program. here it is:

    VB Code:
    1. On Error Resume Next
    2.  
    3. Righto = False
    4.  
    5. DoCheck
    6.  
    7. DoEvents
    8.  
    9. If Righto = True Then Exit Sub
    10.  
    11. Dim i
    12.  
    13. For i = 1 To Outwards
    14.  
    15. BigX = BigX + 4
    16.  
    17. lilX = lilX + 4
    18.  
    19. DoCheck
    20.  
    21. DoEvents
    22.  
    23. If Righto = True Then Exit Sub
    24.  
    25. Next
    26.  
    27. For i = 1 To Outwards
    28.  
    29. BigY = BigY + 4
    30.  
    31. lilY = lilY + 4
    32.  
    33. DoCheck
    34.  
    35. DoEvents
    36.  
    37. If Righto = True Then Exit Sub
    38.  
    39. Next
    40.  
    41. Outwards = Outwards + 2
    42.  
    43. For i = 1 To Outwards
    44.  
    45. BigX = BigX - 4
    46.  
    47. lilX = lilX - 4
    48.  
    49. DoCheck
    50.  
    51. DoEvents
    52.  
    53. If Righto = True Then Exit Sub
    54.  
    55. Next
    56.  
    57. For i = 1 To Outwards
    58.  
    59. BigY = BigY - 4
    60.  
    61. lilY = lilY - 4
    62.  
    63. DoCheck
    64.  
    65. DoEvents
    66.  
    67. If Righto = True Then Exit Sub
    68.  
    69. Next
    70.  
    71. Outwards = Outwards + 2
    72.  
    73. If Outwards > 70 Then
    74.  
    75. BigX = closeX
    76.  
    77. BigY = closeY
    78.  
    79. lilY = Sample.Height \ 2
    80.  
    81. lilX = Sample.Width \ 2
    82.  
    83. Outwards = 0
    84.  
    85. Picture1.Cls
    86.  
    87. End If

    pretty crappy huh? it needs some coding to be done but it might be useful.

    Koen

  11. #11
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    I'd just use getpixel, store the color values in some arrays, and do a comparison - but I guess that's rather slow ?
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  12. #12
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Yea, GetPixel is really slow for some reason, I tried it on a 128x128 image and it took 94ms.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    22
    if i used that it will really take ages, because i have to compare over 10,000 images (257x42) but i still do have a question,if i make a screenshot, there is more on the picture then i want. i just want to compare a small piece of the screenshot with my pictures. how can i do something like this?

    Koen

  14. #14
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: compare images

    Tec-Nico your Piccomp app works great with bmp, gif, jpg etc. But if you load icons into the images you get Subscript out of range in:

    ReDim Bytes1(0 To Bm1.bmWidthBytes - 1, 0 To Bm1.bmHeight - 1)

    Because it can't dimension the array. Any ideas why it can't find the height and width.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  15. #15
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Re: compare images

    I am not quite sure... But it could be that you would need to use different API and even structures.

    Look it up in the API Forums..
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

Posting Permissions

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



Click Here to Expand Forum to Full Width