Jump to content

Compare images


Recommended Posts

I think here I need to put loop/arrays but im not so experienced in this.

Func works very good with two images but I need to compare 10 images.

Always is one main image and need to find same image as main. So if func returns false, loop to other image.

#include



_GDIPlus_Startup()

$mainimage = "C:Documents and SettingsMyDesktopAutoitnewSukarpyti skaiciaic0.bmp" ;main image, this img wont change


$fname1 = "C:Documents and SettingsvDesktopAutoitnewpicturesc1.bmp"


;=========experimenting
$fname2 = "C:Documents and SettingsMyDesktopAutoitnewpicturesc2.bmp"
$fname3 = "C:Documents and SettingsMyDesktopAutoitnewspicturesc3.bmp"
$fname4 = "C:Documents and SettingsMyDesktopAutoitnewpicturesc4.bmp"
$fname5 = "C:Documents and SettingsMyDesktopAutoitnewpicturesc5.bmp"
$fname6 = "C:Documents and SettingsvDesktopAutoitnewpicturesc6.bmp"      ;I think all these need to put into
$fname7 = "C:Documents and SettingsMyDesktopAutoitnewpicturesc7.bmp"     ; array and make loop
$fname8 = "C:Documents and SettingsMyDesktopAutoitnewapicturesc8.bmp"
$fname9 = "C:Documents and SettingsvDesktopAutoitnewpicturesc9.bmp"
$fname10 = "C:Documents and SettingsMyDesktopAutoitnewpicturesc10.bmp"
;=========experimenting

$bm1 = _GDIPlus_ImageLoadFromFile($mainimage) ; dont changes (main img)

;find for same img
$bm2 = _GDIPlus_ImageLoadFromFile($fname2)




MsgBox(0, "bm1==bm2", CompareBitmaps($bm1, $bm2)) ;shows if true or false, if it returns false then need to make to go for another img.


_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

Tried to do very simple, like If it returns false then declare other variable or smth like that. But how to read return value?

;====================================

Edited by EdgarT
Link to comment
Share on other sites

I can see if its true or not with these

iF CompareBitmaps($bm1, $bm2) = False then msgbox(0,"","lol false")

iF CompareBitmaps($bm1, $bm2) = True then msgbox(0,"","lol true")

But how to make to loop throught images?

In primitive way it could be

While 1
;find for smae img
$bm2 = _GDIPlus_ImageLoadFromFile($fname1)

iF CompareBitmaps($bm1, $bm2) = False then
msgbox(0,"","1st one false")
$bm2 = _GDIPlus_ImageLoadFromFile($fname10)
CompareBitmaps($bm1, $bm2)
If CompareBitmaps($bm1, $bm2) = true then MsgBox(0, "bm1==bm2", CompareBitmaps($bm1, $bm2))
Endif
;MsgBox(0, "bm1==bm2", CompareBitmaps($bm1, $bm2))

_GDIPlus_ImageDispose($bm1)
_GDIPlus_ImageDispose($bm2)

WEnd

And I could write this crap in over 50 lines lol

Edited by EdgarT
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...