Results 1 to 11 of 11

Thread: check this code <URGENT>

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2004
    Location
    kota,rajasthan(India)
    Posts
    53

    Exclamation check this code <URGENT>

    HI.........
    I HAVE TO GENERATE A CODE THAT ENABLE TO COMPARE TWO OR MORE IMAGES. BUT I HAVE MANY PROB. TO RUN
    IT GIVES LOGICAL ERRORS MEANS NOT GIVING APPROPIATE OUTPUTS
    PLZ CHECK IT.

    CODE IS :->

    Sub Check()
    Dim boomismatch As Boolean
    Dim x As Integer
    Dim y As Integer
    boomismatch = False
    For y = 1 To Picture1.Height
    For x = 1 To Picture1.Width
    If Picture1.Point(x, y) = Picture2.Point(x, y) Then
    Picture1.PSet (x, y), RGB(255, 0, 0)
    boomismatch = True
    Exit For
    End If
    Next x
    If boomismatch = True Then
    Exit For
    End If
    Next y
    If boomismatch = True Then
    MsgBox "not same"
    c = 0
    Else
    MsgBox "same"
    MsgBox Picture1.Name
    c = 1
    Exit Sub
    End If
    End Sub

    PLZ CHECK IT & SEND IT TO ME. ITS REALLY VERY VERY URGENT 2 ME
    BYE
    Piyush Gupta

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: check this code <URGENT>

    This way it is easier to read:

    VB Code:
    1. Sub Check()
    2.     Dim boomismatch As Boolean
    3.     Dim x As Integer
    4.     Dim y As Integer
    5.  
    6.     boomismatch = False
    7.  
    8.     For y = 1 To Picture1.Height
    9.         For x = 1 To Picture1.Width
    10.             If Picture1.Point(x, y) = Picture2.Point(x, y) Then
    11.                 Picture1.PSet (x, y), RGB(255, 0, 0)
    12.                 boomismatch = True
    13.                 Exit For
    14.             End If
    15.         Next x
    16.        
    17.         If boomismatch = True Then
    18.             Exit For
    19.         End If
    20.     Next y
    21.    
    22.     If boomismatch = True Then
    23.         MsgBox "not same"
    24.         c = 0
    25.     Else
    26.         MsgBox "same"
    27.         MsgBox Picture1.Name
    28.         c = 1
    29.         Exit Sub
    30.     End If
    31. End Sub

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: check this code <URGENT>

    If you want help you should ask nicely and DON'T SCREAM AT US!!!

  4. #4
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: check this code <URGENT>

    You say you're getting an error.
    Maybe you should first test this

    VB Code:
    1. If Picture1.Height <> Picture2.Height or Picture1.Width <> Picture2.Width Then
    2.         'Not a match, do something
    3.     end if

    You may can also make that pixel test faster if you set the scalemode on both PictureBoxes to vbPixels.
    Last edited by longwolf; May 26th, 2005 at 10:34 PM.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2004
    Location
    kota,rajasthan(India)
    Posts
    53

    Re: check this code <URGENT>

    Quote Originally Posted by baja_yu
    This way it is easier to read:

    VB Code:
    1. Sub Check()
    2.     Dim boomismatch As Boolean
    3.     Dim x As Integer
    4.     Dim y As Integer
    5.  
    6.     boomismatch = False
    7.  
    8.     For y = 1 To Picture1.Height
    9.         For x = 1 To Picture1.Width
    10.             If Picture1.Point(x, y) = Picture2.Point(x, y) Then
    11.                 Picture1.PSet (x, y), RGB(255, 0, 0)
    12.                 boomismatch = True
    13.                 Exit For
    14.             End If
    15.         Next x
    16.        
    17.         If boomismatch = True Then
    18.             Exit For
    19.         End If
    20.     Next y
    21.    
    22.     If boomismatch = True Then
    23.         MsgBox "not same"
    24.         c = 0
    25.     Else
    26.         MsgBox "same"
    27.         MsgBox Picture1.Name
    28.         c = 1
    29.         Exit Sub
    30.     End If
    31. End Sub
    but it gives incorrect results
    plz correct it & send it 2 me.
    Piyush Gupta

  6. #6
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: check this code <URGENT>

    Ok well, just going through...

    VB Code:
    1. Sub Check()
    2.     Dim boomismatch As Boolean
    3.     Dim x As Integer
    4.     Dim y As Integer
    5.  
    6.     boomismatch = False
    7.  
    8.     For y = 1 To Picture1.Height
    9.         For x = 1 To Picture1.Width
    10.             If Picture1.Point(x, y) = Picture2.Point(x, y) Then
    11.                 Picture1.PSet (x, y), RGB(255, 0, 0)
    12.             Else
    13.                 boomismatch = True
    14.                 Exit For
    15.             End If
    16.         Next x
    17.        
    18.         If boomismatch = True Then
    19.             Exit For
    20.         End If
    21.     Next y
    22.    
    23.     If boomismatch = True Then
    24.         MsgBox "not same"
    25.         c = 0
    26.     Else
    27.         MsgBox "same"
    28.         MsgBox Picture1.Name
    29.         c = 1
    30.         Exit Sub
    31.     End If
    32. End Sub

    Does that do it?

  7. #7
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: check this code <URGENT>

    You're going to get an error if the pics aren't the same size

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2004
    Location
    kota,rajasthan(India)
    Posts
    53

    Re: check this code <URGENT>

    Quote Originally Posted by Nove
    Ok well, just going through...

    VB Code:
    1. Sub Check()
    2.     Dim boomismatch As Boolean
    3.     Dim x As Integer
    4.     Dim y As Integer
    5.  
    6.     boomismatch = False
    7.  
    8.     For y = 1 To Picture1.Height
    9.         For x = 1 To Picture1.Width
    10.             If Picture1.Point(x, y) = Picture2.Point(x, y) Then
    11.                 Picture1.PSet (x, y), RGB(255, 0, 0)
    12.             Else
    13.                 boomismatch = True
    14.                 Exit For
    15.             End If
    16.         Next x
    17.        
    18.         If boomismatch = True Then
    19.             Exit For
    20.         End If
    21.     Next y
    22.    
    23.     If boomismatch = True Then
    24.         MsgBox "not same"
    25.         c = 0
    26.     Else
    27.         MsgBox "same"
    28.         MsgBox Picture1.Name
    29.         c = 1
    30.         Exit Sub
    31.     End If
    32. End Sub

    Does that do it?
    NOT IG GIVES INCORRECT RESULTS
    I SEND U PROG TO CHECK, OK
    Attached Files Attached Files
    Piyush Gupta

  9. #9
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: check this code <URGENT>

    If you want to check if the images are identical, then the logic is simple:

    1. Compare sizes, if different then they are not the same
    2. If same size, then loop through all pixels and compare if they are the same color.
    3. If at least 1 pair of pixels is not the same color, then the images are not same.

    You can implement some sort of flexibility, for instance, allow 1% of pixels to be different.

  10. #10

    Thread Starter
    Member
    Join Date
    Aug 2004
    Location
    kota,rajasthan(India)
    Posts
    53

    Question Re: check this code <URGENT>

    Quote Originally Posted by baja_yu
    If you want to check if the images are identical, then the logic is simple:

    1. Compare sizes, if different then they are not the same
    2. If same size, then loop through all pixels and compare if they are the same color.
    3. If at least 1 pair of pixels is not the same color, then the images are not same.

    You can implement some sort of flexibility, for instance, allow 1% of pixels to be different.
    i m tring to do this with all things you say into my mind but i cannt get right answer.
    plz check my file
    & send suggestions to me
    Piyush Gupta

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: check this code <URGENT>

    First of all you should set the ScaleMode of the Picture boxes to Pixels so you don't have to loop through a lot of twips and check the same pixel more then once. Secondly use the ScaleWidth and ScaleHeight properties instead of the Height and Width. Thirdly I would wrap this into a more generic function:
    VB Code:
    1. Public Function IdenticImages(pic1 As PictureBox, pic2 As PictureBox) As Boolean
    2.     Dim x As Long
    3.     Dim y As Long
    4.  
    5.     pic1.ScaleMode = vbPixels
    6.     pic2.ScaleMode = vbPixels
    7.     If pic1.ScaleHeight <> pic2.ScaleHeight Or pic1.ScaleWidth <> pic2.ScaleWidth Then
    8.         Exit Function
    9.     End If
    10.     For y = 0 To pic1.ScaleHeight - 1
    11.         For x = 1 To pic1.ScaleWidth - 1
    12.             If pic1.Point(x, y) <> pic2.Point(x, y) Then
    13.                 pic1.PSet (x, y), RGB(255, 0, 0)
    14.                 Exit Function
    15.             End If
    16.         Next x
    17.     Next y
    18.     IdenticImages = True
    19. End Sub
    Now you can simply call this function from your code instead.
    VB Code:
    1. If IdenticImages(Picture1, Picture2) Then
    2.     MsgBox "The pictures are the same!"
    3.     c = 1
    4. Else
    5.     MsgBox "The images are not the same!"
    6.     c = 0
    7. End If
    Now, using Point and PSet are very slow so this function will be slow when comparing large images. You could speed it up a little by using the GetPixel API function instead of the Point statement, but it will still be pretty slow on large images.

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