cxs Posted February 15, 2009 Share Posted February 15, 2009 Hi, I'd like a simple function that can compare 2 jpg images and return a true or false. something like If all pixels in c:\1.jpg = all pixels in c:\2.jpg then ToolTip("image 1 and 2 are the same", 0, 0, "Image Found", 1) Else ToolTip("image 1 and 2 are not the same", 0, 0, "Image Not Found", 1) EndIf I have spent several hours trying to find out how to do this and searched the forums etc, but I haven't been able to make anything that works. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 15, 2009 Moderators Share Posted February 15, 2009 cxs,Search harder - there are lot of examples out there - I found threads suggesting many different approaches on the first page of responses to ""compare+image"!Hints: Look at PixelGetSum. Or you could use PixelGetColor and create 2 arrays. Or you could create suitable hashes to compare and never even have to display the .jpgs.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Manjish Posted February 15, 2009 Share Posted February 15, 2009 Just came up with a rough idea.. u can use it.. just go for the concept.. change whatever u need to make it better.. $hwnd1=WinGetHandle("Image1.jpg","") $hwnd2=WinGetHandle("Image2.jpg","") For $x=0 to 5000 ;WinGetHandle("Image1.jpg","") $image1=PixelGetColor($x,$x,$hwnd1) $image2=PixelGetColor($x,$x,$hwnd2) If @error Then ExitLoop If $image1<>$image2 Then mismatch() ExitLoop EndIf $count=$count+1 Next if $count=$ImageDimension Then MsgBox(4096,"Image match??","Complete match.. success") EndIf Func mismatch() MsgBox(4096,"Image match??","Failed.. Mismatch") EndFunc [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
cxs Posted February 15, 2009 Author Share Posted February 15, 2009 cxs,Search harder - there are lot of examples out there - I found threads suggesting many different approaches on the first page of responses to ""compare+image"!Hints: Look at PixelGetSum. Or you could use PixelGetColor and create 2 arrays. Or you could create suitable hashes to compare and never even have to display the .jpgs.M23the .jpgs are not meant to be displayed, the function need to check the actual jpg files.I've looked at pixelchecksum, but haven't found a way to load and compare 2 images.I've tried alot of different things but the actual solution have eluded me.So I hoped someone could help me with this one.I'll try searching again, but if someone know the solution to this one I'd appreciate it. Link to comment Share on other sites More sharing options...
Manjish Posted February 15, 2009 Share Posted February 15, 2009 the .jpgs are not meant to be displayed, the function need to check the actual jpg files.Not very sure that u can do that.. U'll have to display the images.. as far as my knowledge goes..I mean the image files shud be opened.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 15, 2009 Moderators Share Posted February 15, 2009 cxs,As you do want to display the .jpgs, a search for "compare+files", rather than "compare+image" would have thrown up this thread.As I suggested earlier, it proposes creating hashes to compare.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Manjish Posted February 15, 2009 Share Posted February 15, 2009 $hwnd1=WinGetHandle("Image1.jpg","") $hwnd2=WinGetHandle("Image2.jpg","") $ycount=$xcount=0 For $x=0 to $imagewidth for $y=0 to $imageheight ;WinGetHandle("Image1.jpg","") $image1=PixelGetColor($x,$x,$hwnd1) $image2=PixelGetColor($x,$x,$hwnd2) If @error Then ExitLoop If $image1<>$image2 Then mismatch() ExitLoop EndIf $ycount=$ycount+1 Next $xcount=$xcount+1 Next if $xcount=$imagewidth And $ycount=$imageheight Then MsgBox(4096,"Image match??","Complete match.. success") EndIf Func mismatch() MsgBox(4096,"Image match??","Failed.. Mismatch") EndFunc As far as i see this should do the required job.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
cxs Posted February 15, 2009 Author Share Posted February 15, 2009 Thanks to the both of you for your help. I'll go through your example and search some more and come up with a solution. Even if I didn't get what I needed I'm closing this topic. thanks Link to comment Share on other sites More sharing options...
monoceres Posted February 15, 2009 Share Posted February 15, 2009 ; Retarded code here As far as i see this should do the required job.. Seriously? Why don't you test that "code" and see how it work out. I mean, it seem so logical to compare two images by using WinGetHandle(). Here's something that actually works, and not only that, also work even if the images are in different formats and have different tags etc. expandcollapse popup#include <GDIPlus.au3> _GDIPlus_Startup() $fname1=FileOpenDialog("First image","","All images(*.bmp;*.jpg;*.png;)") If $fname1="" Then Exit $fname2=FileOpenDialog("Second image image","","All images(*.bmp;*.jpg;*.png;)") If $fname2="" Then Exit $bm1 = _GDIPlus_ImageLoadFromFile($fname1) $bm2 = _GDIPlus_ImageLoadFromFile($fname2) MsgBox(0, "bm1==bm2", CompareBitmaps($bm1, $bm2)) _GDIPlus_ImageDispose($bm1) _GDIPlus_ImageDispose($bm2) _GDIPlus_Shutdown() Func CompareBitmaps($bm1, $bm2) $Bm1W = _GDIPlus_ImageGetWidth($bm1) $Bm1H = _GDIPlus_ImageGetHeight($bm1) $BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB) $Stride = DllStructGetData($BitmapData1, "Stride") $Scan0 = DllStructGetData($BitmapData1, "Scan0") $ptr1 = $Scan0 $size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4 $Bm2W = _GDIPlus_ImageGetWidth($bm2) $Bm2H = _GDIPlus_ImageGetHeight($bm2) $BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB) $Stride = DllStructGetData($BitmapData2, "Stride") $Scan0 = DllStructGetData($BitmapData2, "Scan0") $ptr2 = $Scan0 $size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4 $smallest = $size1 If $size2 < $smallest Then $smallest = $size2 $call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest) _GDIPlus_BitmapUnlockBits($bm1, $BitmapData1) _GDIPlus_BitmapUnlockBits($bm2, $BitmapData2) Return ($call[0]=0) EndFunc ;==>CompareBitmaps Alexxander 1 Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
cxs Posted February 16, 2009 Author Share Posted February 16, 2009 quote name='monoceres' date='Feb 15 2009, 09:56 PM' post='644671' Thanks alot Monoceres Link to comment Share on other sites More sharing options...
VAG Posted July 28, 2009 Share Posted July 28, 2009 (edited) Hi Monoceres, I am working on to compare some webcam images with minor differences due to noise. May i know how this code is doing the compare? You mentioned that it works on images with different formats. Is there a tolerance in the comparison? Edited July 28, 2009 by VAG Link to comment Share on other sites More sharing options...
monoceres Posted July 28, 2009 Share Posted July 28, 2009 My code is just doing a byte for byte comparison of the image data using the visual c runtime function memcmp. So the images have the exactly match. If you wish to compare the data yourself you will have to loop through the data. Search the forums for _GDIPlus_BitmapLockBits for examples. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Zedna Posted July 28, 2009 Share Posted July 28, 2009 (edited) I successfuly used Prospeed and its CompareBytes() function for comparing images also with tolerance parameter. It returns number of different bytes. concept: LoadFileImage() InitFX() CompareBytes() Search Prospeed in Examples forum. BTW: very nice function CompareBitmaps() monoceres!! Edited July 28, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now