Jump to content
Sign in to follow this  
Orgins

Is there a faster way to compare jpgs?

Recommended Posts

Orgins

I been using/playing around with this compare func (posted below I did not make it someone else did). It works perfect but I use it to compare 50+ small jpgs (taking about 30 secs) then if none of those jpgs match I use it to compare 50+ larger jpgs (taking up 80-90 secs).

I use it as a basic pickit if it matches a small jpg (only part of the items name (which weeds out 70% of all unwanted items)) it skips that item but if it doesn't math then the larger jpgs are compared (to weed out the 90%+ of all unwanted items). It works perfect but it takes up so much time.

Is there faster way to compare them?

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
Edited by Orgins

I'm a newbie.Sorry if I don't reposed to your replays very fast.

Share this post


Link to post
Share on other sites
Siao

I can think of a couple ways to do this using GDI, but why not simply use PixelChecksum?


"be smart, drink your wine"

Share this post


Link to post
Share on other sites
Orgins

I don't understand the GDI stuff. Ill read up on it.

Don't think pixelchecksum would work. Some times the items name is nerf'ed (small different in the size of the name/image) so the checksum might be way off. I use the compare func to see if it matches 95% or more so if theres a small nerf in the item itll still pick/skip it as wanted.


I'm a newbie.Sorry if I don't reposed to your replays very fast.

Share this post


Link to post
Share on other sites
Orgins

Grr something else I don't understand (never messed with .Net before). From what i've read it sounds like it'll work for my need.

I've gota turn some trees into wood chips so afk awhile. I'll post/bump latter if I need more help.


I'm a newbie.Sorry if I don't reposed to your replays very fast.

Share this post


Link to post
Share on other sites
weaponx

Grr something else I don't understand (never messed with .Net before). From what i've read it sounds like it'll work for my need.

I've gota turn some trees into wood chips so afk awhile. I'll post/bump latter if I need more help.

Okay this is probably better, you can use ImageMagick from the command line to perform the compare:

http://www.imagemagick.org/script/compare.php

It will return a numerical metric which describes the level of difference.

Edited by weaponx

Share this post


Link to post
Share on other sites
jpam

prospeed has a compare function.

does a 800x600 picture compare under 2 ms

if you want i can give you a example code

Share this post


Link to post
Share on other sites
weaponx

prospeed has a compare function.

does a 800x600 picture compare under 2 ms

if you want i can give you a example code

Will it provide a percentage of difference? Or will it only find an exact match?

Share this post


Link to post
Share on other sites
jpam

you can set the amout off bytes that may differ

Share this post


Link to post
Share on other sites
jpam

#include <prospeed3.0.au3>

Opt("GUIOnEventMode", 1)

Dim $array1,$array2

GUICreate("Compare 2 images", 800, 350)
GUISetOnEvent(-3, "_exit")
$label1 = GUICtrlCreateLabel("", 20, 310, 500, 20)
$label2 = GUICtrlCreateLabel("", 20, 330, 500, 20)
GUISetState()

$hdc = GetHDC() ; Get Window hDC

$pic1 = LoadFileImage("Cancun-beach400.jpg") ; Load  image from disk
$pic2 = LoadFileImage("Cancun-beach400.jpg") ; Load  image from disk
$size = 400*3*300 ; Size of Image (Width * 3 bytes * Height)

$array1 = InitFX($pic1) ; Create Array data from loaded Image

; Create struct For Array info data
$arrayInfos1  = DllStructCreate("long;long;long;dword;dword;long;long;long;long;long;long;long", $array1)
$Pointer1     = DllStructGetData($arrayInfos1, 11) ; Get pointer from array

$test = CreateImage(20, 20) ; Create test Image
ColorFillImage($test, 0, 0, 20, 20, 0xFFFFFF) ; Fill Image with white color
$tmp = InitFX($test) ; Create Array data from test image

CreateBuffer(400, 300) ; Create screenbuffer for WM_PAINT
SetBuffer($pic1) ; set buffer for WM_PAINT

CopyFX($hdc, 0, 0, $array1)   ; Copy Array data to screen
CopyFX($hdc, 400, 0, $array1)

Func start()
    $array2 = InitFX($pic2) ; Create array data form pic 2
    
    ; Create struc for array data info
    $arrayInfos2  = DllStructCreate("long;long;long;dword;dword;long;long;long;long;long;long;long", $array2)
    $Pointer2     = DllStructGetData($arrayInfos2, 11) ; Get Ponter for array data 2
    
    ; copy at random position test pic to array data 2
    BitBltArray($array2, Random(0,350,1), Random(0,280,1), 20, 20, $tmp, 0, 0, 0) 

    CopyFX($hdc, 400, 0, $array2) ; copy array data 2 to screen
    
    $time = TimerInit() ; start timer
    
          ; CompareBytes(Pointer1, Pointer2, bytes, tolerance in bytes)
    $chk2 = CompareBytes($Pointer1, $Pointer2, $size, 250) ; compare the 2 array data's with a tolerance of 250 bytes

    $stop = TimerDiff($time) ; stop timer
    
    GUICtrlSetData($label1, "Time = "&$stop)    
    GUICtrlSetData($label2, "Different Bytes = "&$chk2)
    
    FreeFX($array2) ; free array data from memory
EndFunc

While 1
    Sleep(500) ; you can remove sleep to see how fast it compares
    start()
WEnd

Func _exit()
    $Struct1 = ""   ; Clear struct1
    $Struct2 = ""   ; Clear struct2
    FreeAllImages() ; free all bitmaps from memory
    FreeFX($array1) ; free array data 1 from memory
    FreeFX($array2) ; free array data 2 from memory
    DestroyBuffer() ; free screen buffer from memory
    Exit
EndFunc

picture i used

post-5777-1211234260_thumb.jpg

Share this post


Link to post
Share on other sites
Orgins

Thinks for the help/info. I banged up my hand so I don't feel like typing/playing with them atm.

Where can I get prospeed3.0.au3? I searched for it but didn't find it.

/edit Woot I'm an "Advanced Member" now.

Edited by Orgins

I'm a newbie.Sorry if I don't reposed to your replays very fast.

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  

×