Jump to content



Photo

Compare Pictures


  • Please log in to reply
7 replies to this topic

#1 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 04 November 2007 - 08:54 PM

Recording all pixels colors in pictures one by one and comparing how many pixel colors match. Giving percentage of how many true pixel color match and true pixel color match count. ( Sorry for my bad script description but my English not enough for explain that :"> ) By the way im curious about how can i capture pixel colors in picture without open in gui, so that process will be more fast.

$Test = Compare ( First Picture, Second Picture, Picture Width, Picture Height, Search Step )
$Test[0] = Total searched pixels in picture
$Test[1] = Percentage of equal pixel color
$Test[2] = Equal pixel color count
$Test[3] = Not equal pixel color count

AutoIt         
#include <GUIConstants.au3> Opt("PixelCoordMode", 2) Global $Data For $i = 1 To 4     $Test = Compare("Test1.jpg", "Test" & $i & ".jpg", 75, 75, 10)     If $Data = "" Then         $Data = "Test" & $i & ".jpg  " & $Test[1] & "% Total : " & $Test[0] & " Equal : " & $Test[2] & " Not Equal : " & $Test[3]     Else         $Data = $Data & @CRLF & "Test" & $i & ".jpg  " & $Test[1] & "% Total : " & $Test[0] & " Equal : " & $Test[2] & " Not Equal : " & $Test[3]     EndIf     If $Test[1] = 100 Then $Found = "Test" & $i & ".jpg" Next MsgBox("", "", $Data) If $Found <> "" Then MsgBox("", "", $Found & " 100% match!") Func Compare($Pic1, $Pic2, $Width, $Height, $Step = 1)     Local $Color[$Width + 1][$Height + 1], $Color2[$Width + 1][$Height + 1], $Var = 0, $Var2 = 0     $Compare = GUICreate("", $Width, $Height, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)     GUISetState(@SW_SHOW, $Compare)     $Pic = GUICtrlCreatePic($Pic1, "", "", $Width, $Height)     For $y = 1 To $Height Step $Step         For $x = 1 To $Width             $Color[$x][$y] = PixelGetColor($x, $y)         Next     Next     GUICtrlSetImage($Pic, $Pic2)     For $y = 1 To $Height Step $Step         For $x = 1 To $Width             $Color2[$x][$y] = PixelGetColor($x, $y)             If $Color[$x][$y] = $Color2[$x][$y] Then                 $Var += 1             Else                 $Var2 += 1             EndIf         Next     Next     $Need = $Var + $Var2     $Result = ($Var / $Need) * 100     GUIDelete($Compare)     Dim $Return[4] = [$Need, Round($Result, 1), $Var, $Var2]     Return $Return EndFunc   ;==>Compare

Attached Files


Edited by Jex, 05 November 2007 - 01:02 AM.








#2 Nahuel

Nahuel

    To Err is human, to Arr is pirate.

  • Active Members
  • PipPipPipPipPipPip
  • 1,841 posts

Posted 04 November 2007 - 09:29 PM

Hey man! Good work <_< works great!

#3 Nahuel

Nahuel

    To Err is human, to Arr is pirate.

  • Active Members
  • PipPipPipPipPipPip
  • 1,841 posts

Posted 04 November 2007 - 11:18 PM

Hey, I made this cos I really liked the idea. I'm planning on working more on it though.
AutoIt         
#include <GUIConstants.au3> Opt("PixelCoordMode", 2) Global $Color=0xEF0000 Global $Pic Global $U32 Global $GDI GUICreate("", 313, 201) $Path1 = GUICtrlCreateInput("Muestra2.bmp", 24, 48, 193, 21) $Path2 = GUICtrlCreateInput("Muestra1.bmp", 24, 92, 193, 21) $Browse1 = GUICtrlCreateButton("Browse", 226, 48, 61, 23, 0) $Browse2 = GUICtrlCreateButton("Browse", 226, 92, 61, 23, 0) $compare = GUICtrlCreateButton("&Compare", 95, 152, 127, 31, $BS_DEFPUSHBUTTON) GUICtrlCreateGroup(" Paths ", 8, 14, 293, 123) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE             Exit         Case $Browse1             $newPath=FileOpenDialog("",@MyDocumentsDir,"(*.jpg;*bmp)")             if Not @error Then                 GUICtrlSetData($Path1,$newPath)             EndIf         Case $Browse2             $newPath=FileOpenDialog("",@MyDocumentsDir,"(*.jpg;*bmp)")             if Not @error Then                 GUICtrlSetData($Path2,$newPath)             EndIf         Case $compare             $Pic1Path=GUICtrlRead($Path1)             $Pic2Path=GUICtrlRead($Path2)             $U32=DllOpen("user32.dll")             $GDI=DllOpen("GDI32.dll")             $Test = Compare($Pic1Path,$Pic2Path, 200,200)             DllClose($U32)             DllClose($U32)             MsgBox(4144,"",$Test)     EndSwitch WEnd Func Compare($Pic1, $Pic2, $Width, $Height)     Local $Color[$Width + 1][$Height + 1], $Color2[$Width + 1][$Height + 1], $Var = 0     $Test = GUICreate("", $Width, $Height, -1, -1, $WS_POPUP,$WS_EX_TOPMOST)     GUISetState()         $Pic = GUICtrlCreatePic($Pic1, "", "", $Width, $Height)         For $y = 1 To $Height         For $x = 1 To $Width             $Color[$x][$y] = PixelGetColor($x, $y)         Next     Next     GUICtrlSetImage($Pic, $Pic2)     For $y = 1 To $Height         For $x = 1 To $Width             $Color2[$x][$y] = PixelGetColor($x, $y)             If $Color[$x][$y] = $Color2[$x][$y] Then                 $Var += 1             Else                 dibujar($x,$y)             EndIf         Next     Next     $Need = $Height * $Width     $Result = ($Var / $Need) * 100 ;~     GUIDelete($Test)     Return Round($Result, 1) & "%  " & $Var EndFunc   ;==>Compares Func dibujar($nX,$nY)     $hand = DllCall($U32,"int", "GetDC", "hwnd",GUICtrlGetHandle($Pic)); 0)     $pen = DllCall($GDI, "int", "CreatePen", "int", 0 , "int",2, "int", $Color)     DllCall($GDI, "int", "SelectObject", "int", $hand[0], "int", $pen[0])     DllCall($GDI, "int", "MoveToEx", "hwnd", $hand[0], "int",$nX, "int", $nY, "int", 0)     DllCall($GDI, "int", "LineTo", "hwnd", $hand[0], "int", $nX, "int", $nY) EndFunc


You can browse to select two pictures you want to compare. When it finds a different pixel, it will spot it. The very annoying problem is that the pic gui needs to have focus always and it gets REALLY slow, obviously, when trying to compare two pics that are totally different.

Download these two images and place them in the same directory as the script to test it, you'll see clearly what it does.
http://nahueljose.googlepages.com/Muestra1.bmp
http://nahueljose.googlepages.com/Muestra2.bmp

#4 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 04 November 2007 - 11:38 PM

Dibujar ( By the way what is Dibujar <_< ) function very nice but slowing searching speed much i think?
First picture scan 1100ms, second picture scan 2100ms.

#5 Nahuel

Nahuel

    To Err is human, to Arr is pirate.

  • Active Members
  • PipPipPipPipPipPip
  • 1,841 posts

Posted 04 November 2007 - 11:42 PM

Yes, that's another problem...
(Dibujar means 'to draw')

#6 _Kurt

_Kurt

    I can only imagine the world without Autoit (see above)

  • Active Members
  • PipPipPipPipPipPip
  • 865 posts

Posted 05 November 2007 - 12:10 AM

By the way im curious about how can i capture pixel colors in picture without open in gui, so that process will be more fast.

Yes, I've been wondering about that too.

And maybe add a parameter controlling the Step in the For..Next loop so the user has the option to skip every X pixel (for speed, of course).

Kurt
Awaiting Diablo III..

#7 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 05 November 2007 - 12:32 AM

Yes, I've been wondering about that too.

And maybe add a parameter controlling the Step in the For..Next loop so the user has the option to skip every X pixel (for speed, of course).

Kurt


Thanks for your suggestion, i'm added $Step parameter.

#8 ngocs2tron

ngocs2tron

    Seeker

  • Active Members
  • 16 posts

Posted 05 November 2010 - 10:58 AM

i can't open popup




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users