Sign in to follow this  
Followers 0
michaelslamet

How to verify that 2 images are identical?

6 posts in this topic

I am taking few screenshots using:

_ScreenCapture_CaptureWnd

and then save it using:

_ScreenCapture_SaveImage

When the last 2 images are identical, my script will break the loop.

The questions is how to verify that  2 images are identical?

I was thinking using CRC32 to check the files checksum but my small experiment show that

_ScreenCapture_SaveImage give a different file size for 2 same images.

Share this post


Link to post
Share on other sites



UEZ probably has a snippet lying around that will do it..

But if you want a head start this is what it looks like in VB

I wish I had time to play with it.. :-(

http://www.vbforums.com/showthread.php?6972-Determining-if-two-pictures-are-identical&p=1484338&viewfull=1#post1484338

Bill

Share this post


Link to post
Share on other sites

I have a function that is laying around someone on the Forum to create a MD5 hash. If the filesize is different then the files aren't identical.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I use _ImageSearch (function found in this forum).

Ccreate two HBITMAPs with _ScreenCapture_Capture and search for the first one in the second one. If the result is 1 they are identical.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this: 

Not the fastest way to compare if you want to check a lot of images. Otherwise save the image, e.g. alwasy as BMP and compare it with MD5 if they have same size.

If you want more information about the differencies than you have to compare pixel by pixel as done in the link above.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Thanks all for reply and help :)

@guinness: in fact, I've been using  your _MD5Hash function for a while and found it very useful :)

On my post #1, I said "my small experiment show that _ScreenCapture_SaveImage give a different file size for 2 same images".

I think I found the problem:

1. I use _ScreenCapture_CaptureWnd with parameter "true" for the cursor, so it will capture the mouse pointer too.

When the pointer moved, the result file (screenshot) will be different (obviously).

2. On the second capture, I activate the window again using WinActivate.

Sometime (not always) this will give a different screenshot, maybe the title of the window flash or something like that.

Anyway, here is the code:

#include <ScreenCapture.au3>
#include <Crypt.au3>

$file1 = "c:\temp\ttt.png"
$file2 = "c:\temp\sss.png"

FileDelete($file1)
FileDelete($file2)

While NOT WinExists("[TITLE:Untitled - Notepad]")
    Run("notepad.exe")
    Sleep(100)
WEnd

$ActiveWindow = WinGetHandle("[TITLE:Untitled - Notepad]")
WinActivate($ActiveWindow)
$tmp = WinGetClientSize("[TITLE:Untitled - Notepad]")
$Image = _ScreenCapture_CaptureWnd ("", $ActiveWindow, 0, 0, $tmp[0], $tmp[1]+200, false)
_ScreenCapture_SaveImage ($file1, $Image, True)

Sleep(2000)

$tmp = WinGetClientSize("[TITLE:Untitled - Notepad]")
$Image = _ScreenCapture_CaptureWnd ("", $ActiveWindow, 0, 0, $tmp[0], $tmp[1]+200, false)
_ScreenCapture_SaveImage ($file2, $Image, True)

If _MD5Hash($file1,100) = _MD5Hash($file2,100) Then
    MsgBox(0, "", "Filesize of file1 = " & FileGetSize($file1) & @CRLF & "Filesize of file2 = " & FileGetSize($file2) & @CRLF &  "File is identical")
Else
    MsgBox(0, "", "Filesize of file1 = " & FileGetSize($file1) & @CRLF & "Filesize of file2 = " & FileGetSize($file2) & @CRLF &  "File is NOT identical!!")
EndIf

; By guinness - 2012-2013.
Func _MD5Hash($sFilePath, $iPercentageRead = Default) ; Default is 100 percent.
    $iPercentageRead = Int($iPercentageRead)
    If ($iPercentageRead > 100) Or ($iPercentageRead < 0) Then
        $iPercentageRead = 100
    EndIf
    Return _Crypt_HashData(FileRead($sFilePath, ($iPercentageRead / 100) * FileGetSize($sFilePath)), $CALG_MD5)
EndFunc   ;==>_MD5Hash

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0