Sign in to follow this  
Followers 0
saurabh2k26

compare all images of a folder with all images of another folder.

12 posts in this topic

Hi

I have X number of images in D:/base and X number of images in D:/test.

All images have same format and size and sorted alphabetically in both folders.

I want to compare 1st image of D:/base with 1st image of D:/test, 2nd of D:/base with 2nd of D:/test and so on and save result in excel(or any other file, aim is just to get final report for all X images).

Since my folders and files are fixed, i dont want unnecessary functions like FileOpenDialog, just all result in single function call.

please help.

Also, if you know some other tool for this function is ok.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to AutoIt and the forum!

Do all the pictures in D:/base and D:/test have the same name? Means: Do you want to compare the content of the files or the content of the directories (= list of names)?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

saurabh2k26,

Welcome to the AutoIt forum. :)

I would get the hash for each of the file contents and then compare them. Look at the following functions in the Help file:

 

_FileListToArray - to list the files

FileRead - to get their contents

_Crypt_HashData - to get the hash

For...Next - to run the necessary loops

Give it a go yourself and see how you get on - you know where we are if you need a bit of help. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I've used WinMerge to compare the content of all files (images) in two directories.

I wanted to check for new pictures for the companies directory.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@Water

D:/base have names as 1.jpg, 2.jpg etc.

D:/test are actually gdi_snapshots taken at different time during a test and have names in format of date and time ex 2013-12-12T23hh13mm44sec.jpg, 2013-12-12T23hh15mm22sec.jpg.

I want to compare image where 1.jpg is expected image of a test and 2013-12-12T23hh13mm44sec.jpg is actual image i got during running the test.

@Melba

Thanks for your help.

Actually, i am very new to autoit. It would be great if you can help with full code.

Share this post


Link to post
Share on other sites

saurabh2k26,

 

It would be great if you can help with full code

We do not normally do that here, we help you develop your own code - think of the old saying: "Give a man a fish, you feed him for a day; give a man a net and you feed him forever". We try to be net makers and repairers, not fishmongers. ;)

But here is a rough idea of what "full code" should look like - I have not tested it:

#include <File.au3>
#include <Crypt.au3>

Global $sPath_Base = "D:/base"
Global $sPath_Base = "D:/test"

_Crypt_Startup()

; Hash the base files
$aList_Base = _FileListToArray($sPath_Base, "*", 1)
Global $aHash_Base = [$aList_Base[0] + 1]
For $i = 1 To $aList_Base[0]
    $sRead = FileRead($sPath_Base  & "\" & $aList_Base[$i])
    $aHash_Base[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next

; Hash the test files
$aList_Test = _FileListToArray($sPath_Test, "*", 1)
Global $aHash_Test = [$aList_Test[0] + 1]
For $i = 1 To $aList_Test[0]
    $sRead = FileRead($sPath_Test & "\" & $aList_Test[$i])
    $aHash_Test[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next

; Now we compare them
For $i = 1 To $aList_Test[0]
    ; Compare this image with all the test images
    For $j = 1 To $aList_Base[0]
        ; If we find a match
        If $aHash_Test[$i] = $aHash_Base[$j] Then
            ; Say so 
            ConsoleWrite($aList_Test[$i] & " matches " & $aList_Base[$j] & @CRLF)
            ; And move on to the next test image
            ExitLoop
        EndIf
    EndIf
    ; Check for a nil return
    If $j > $aList_Base[0] Then
        ConsoleWrite($aList_Test[$i] & " matched no base images" & @CRLF)
    EndIf
Next

ConsoleWrite("All done" & @CRLF)

_Crypt_Shutdown()
Give it a try and see if it works for you. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi Melba

 

I removed few syntax error from your code and run, but ti does not work. In console, all i get is "All done".

#include <File.au3>
#include <Crypt.au3>
 
Global $sPath_Base = "D:\base"
Global $sPath_Test = "D:\test"
 
_Crypt_Startup()
 
; Hash the base files
$aList_Base = _FileListToArray($sPath_Base, "*", 1)
Global $aHash_Base = "[$aList_Base[0] + 1]"
For $i = 1 To "$aList_Base[0]"
    $sRead = FileRead($sPath_Base  & "\" & $aList_Base[$i])
    $aHash_Base[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next
 
; Hash the test files
$aList_Test = _FileListToArray($sPath_Test, "*", 1)
Global $aHash_Test = "[$aList_Test[0] + 1]"
For $i = 1 To "$aList_Test[0]"
    $sRead = FileRead($sPath_Test & "\" & $aList_Test[$i])
    $aHash_Test[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next
 
; Now we compare them
For $i = 1 To "$aList_Test[0]"
    ; Compare this image with all the test images
    For $j = 1 To "$aList_Base[0]"
        ; If we find a match
        If $aHash_Test[$i] = $aHash_Base[$j] Then
            ; Say so 
            ConsoleWrite($aList_Test[$i] & " matches " & $aList_Base[$j] & @CRLF)
            ; And move on to the next test image
            ExitLoop
        EndIf
    ;EndIf
Next
    ; Check for a nil return
    If $j > $aList_Base[0] Then
        ConsoleWrite($aList_Test[$i] & " matched no base images" & @CRLF)
    EndIf
 Next
 
ConsoleWrite("All done" & @CRLF)
 
_Crypt_Shutdown()
Edited by Melba23
Added tags

Share this post


Link to post
Share on other sites

saurabh2k26,

I did say I had not tested it. And there were a couple more silly mistakes you missed. ;)

To make up for it, this script has been tested on my system with my images - and it works perfectly:

#include <File.au3>
#include <Crypt.au3>

Global $sPath_Base = "D:\base"
Global $sPath_Test = "D:\test"

_Crypt_Startup()

; Hash the base files
$aList_Base = _FileListToArray($sPath_Base, "*", 1)
Global $aHash_Base[$aList_Base[0] + 1]
For $i = 1 To $aList_Base[0]
    $sRead = FileRead($sPath_Base & "\" & $aList_Base[$i])
    $aHash_Base[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next

; Hash the test files
$aList_Test = _FileListToArray($sPath_Test, "*", 1)
Global $aHash_Test[$aList_Test[0] + 1]
For $i = 1 To $aList_Test[0]
    $sRead = FileRead($sPath_Test & "\" & $aList_Test[$i])
    $aHash_Test[$i] = _Crypt_HashData($sRead, $CALG_MD5)
Next

; Now we compare them
For $i = 1 To $aList_Test[0]
    ; Compare this image with all the test images
    For $j = 1 To $aList_Base[0]
        ; If we find a match
        If $aHash_Test[$i] = $aHash_Base[$j] Then
            ; Say so
            ConsoleWrite($aList_Test[$i] & " matches " & $aList_Base[$j] & @CRLF)
            ; And move on to the next test image
            ExitLoop
        EndIf
    Next
    ; Check for a nil return
    If $j > $aList_Base[0] Then
        ConsoleWrite($aList_Test[$i] & " matched no base images" & @CRLF)
    EndIf
Next

ConsoleWrite("All done" & @CRLF)

_Crypt_Shutdown()
All good now? :)

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba

Thanks a lot.

I used it in my application and i still need little more help.

Issue1: I run my code by directly clicking my test.au3 and not by opening editor and then Go. So, i am not able to see the console. Can i somehow generate my output to excel file or notepad?

Issue2:

I want to match image 1 of D:base with image 1 of D:test (All images are sorted by name), but i observed that your code matched image 1 of D:/test with all images of D:/base.

My result:

12-09-2013_@_1h53m30s%.jpg matches 1.jpg
12-09-2013_@_1h53m34s%.jpg matches 2.jpg
12-09-2013_@_1h53m41s%.jpg matches 3.jpg
12-09-2013_@_1h53m45s%.jpg matches 4.jpg
12-09-2013_@_1h53m54s%.jpg matches 5.jpg
12-09-2013_@_1h54m01s%.jpg matches 1.jpg
12-09-2013_@_1h54m05s%.jpg matches 7.jpg
 
For red part, i wanted "no base image found" since it do not match 6.jpg
 

Share this post


Link to post
Share on other sites

saurabh2k26,

 

Can i somehow generate my output to excel file or notepad?

Of course. Use Run to open Notepad and then Send to pass what was being written to the console to the app. :)

 

I want to match image 1 of D:base with image 1 of D:test (All images are sorted by name)

Then change the compare code to read like this:

; Now we compare them
For $i = 1 To $aList_Test[0]
    ; Compare this image with the relevant test image
    If $aHash_Test[$i] = $aHash_Base[$i] Then
        ConsoleWrite($aList_Test[$i] & " matches " & $aList_Base[$i] & @CRLF)
    Else
        ConsoleWrite($aList_Test[$i] & " does not match " & $aList_Base[$i] & @CRLF)
    EndIf
Next
I have not tested it - I am on my phone in a hospital waiting room - but it should work. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks, it worked perfectly fine.

Share this post


Link to post
Share on other sites

saurabh2k26,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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