Jump to content

comparison of two images


Recommended Posts

Hi,

i want to compare two images, either for identity or similarity. Is there a nice solution?

What im trying so far is compositing them with Imagmagick and then comparing the composited one with one of the source pictures:

$ImageMagickObj.composite("C:\test.bmp", "C:\test2.bmp", "C:\result.bmp")

$ImageMagickObj.compare("-metric", "MEPP", "C:\result.bmp", "C:\test.bmp", "C:\result2.bmp")

Problem is that

$Metric = $ImageMagickObj.compare("-metric", "MEPP", "C:\result.bmp", "C:\test.bmp", "C:\result2.bmp")

doesnt return the metric value?

Link to comment
Share on other sites

As it are BMP files you can take a look at

http://www.autoitscript.com/forum/index.ph...=66545&st=0

When you read the BMP files into a binary/string you can compare the RGB values yourself into a comparison method of your own.

The problem is i have 52 pictures for 52 cards, so i have to compare the made screenshot with all of them in the worst case? So i need something that is less cpu intensive. I tried imagemagick. With compare command i can retrieve a metric value in db in cmd, how do i get the return value from it when i use

$ImageMagickObj.compare("-metric", "MEPP", "C:\cards\herz2.bmp", "C:\cards\herz4.bmp", "C:\result.bmp") ?

$metricValue = $ImageMagickObj.compare("-metric", "MEPP", "C:\cards\heart2.bmp", "C:\screenshot.bmp", "C:\result.bmp")

delivers only empty strings, but the result.bmp is created. Any idea how i can access the metric? In cmd it returns 0 for identical images and so on

Edited by tylerdurden78
Link to comment
Share on other sites

I think pixelchecksum can do the job you want and is not as resourceintensive as you suggest.

For each of the 52 cards create a pixelchecksum and store the value somewhere.

Then when a card is shown you compare against a table with all 52 predetermined pixelchecksum values.

Even comparing images will not be very cpu intensive as I assume the pictures are relatively small in size and you can do the comparison on low color bitmaps.

Link to comment
Share on other sites

i did some picture comparing in prospeed

replace the jpg's with your own pictures in these lines;

$pic1 = LoadFileImage("Cancun-beach400.jpg")

$pic2 = LoadFileImage("Cancun-beach400.jpg")

size of the pictures is not important , they are resized in the script to 400X300 pixels

the return value is the amout of bytes that differ from the 2 pictures

you can set the tollerance of the compare function in bytes

need prospeed30.dll and prospeed30 udf

download @ http://prospeed-jan.xprofan.com/list-all-downloads.php

#include <prospeed30.au3>

Opt("GUIOnEventMode", 1)

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

$load1 = LoadFileImage("Cancun-beach400.jpg") ; Load  image from disk
$load2 = LoadFileImage("Cancun-beach400.jpg") ; Load  image from disk

$getwidth1  = GetWidthImage($load1)  ; get image width image 1
$getheight1 = GetHeightImage($load1) ; get image height image 1
$getwidth2  = GetWidthImage($load2)  ; get image width image 2
$getheight2 = GetHeightImage($load2) ; get image height image 2

$pic1 = CreateImage(400,300) ; create empty bitmap 1
$pic2 = CreateImage(400,300) ; create empty bitmap 2

SizeImage($pic1,0,0,400,300,$load1,0,0,$getwidth1,$getheight1,0) ; resize image and copy to empty bitmap 1
SizeImage($pic2,0,0,400,300,$load2,0,0,$getwidth2,$getheight2,0) ; resize image and copy to empty bitmap 2

$size = 400*3*300 ; Size of Image (Width * 3 bytes * Height)

$array1 = InitFX($pic1) ; Create Array data from loaded Image
$array2 = InitFX($pic2) ; Create array data form 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 for array1 @ long 11

; 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 Pointer for array2 @ long 11

$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 first time
CopyFX($hdc, 400, 0, $array1) ; Copy Array data to screen first time

Func start()
    $time = TimerInit() ; start timer
    ; copy at random position test pic to array data 2
    BitBltArray($array1, Random(0,350,1), Random(0,280,1), 20, 20, $tmp, 0, 0, 0) 

    CopyFX($hdc, 400, 0, $array1) ; copy array data 2 to screen
    
          ; CompareBytes(Pointer1, Pointer2, bytes, tolerance in bytes)
    $Compare = CompareBytes($Pointer1, $Pointer2, $size, 0) ; compare the 2 array data's with a tolerance of 0 bytes

    $stop = TimerDiff($time) ; stop timer
    
    BitBltArray($array1, 0, 0, 400, 300, $array2, 0, 0, 0) ; copy array2 to array1
    
    GUICtrlSetData($label1, "Time = "&$stop)    
    GUICtrlSetData($label2, "Different Bytes = "&$Compare)
EndFunc

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

Func _exit()
    $arrayInfos1 = ""   ; Clear struct1
    $arrayInfos2 = ""   ; 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
Edited by jpam
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...