getRectCheckSum Issue

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
klcmay
Newbie
Posts: 16
Joined: Sun Jun 01, 2008 10:12 pm

getRectCheckSum Issue

Post by klcmay » Sun Jun 01, 2008 10:31 pm

Hi all,

I am having a problem using getRectChecksum and I would be grateful for some help.

Essentially I have several images on the screen which I wish to compare to check to see if they are a "known" image i.e. one I have previously recorded a checksum of. The images are all on the same y co-ordinates and are separated by a fixed distance on the x-axis between each image.

I think the code is self explanatory:

#The top and bottom of the images
Let>y1=151
Let>y2=168

#The left and right of the first image
Let>img1x1=167
Let>img1x2=175

#get the checksum for 1st image
getRectCheckSum>%img1x1%,%y1%,%img1x2%,%y2%,res1

#second (and subsequent) images are 30 pixels further on
Let>xInc=30
Let>img2x1={%img1x1%+%xInc%}
Let>img2x2={%img1x2%+%xInc%}

#get the checksum for 2nd image
getRectCheckSum>%img2x1%,%y1%,%img2x2%,%y2%,res2

Now the problem is that if I put exactly the same image in both the positions that I am looking at, the checksums generated do not match. Ie res1 != res2 although the images are identical.

There are reasons why I want to do things this way which I wont go into... but suffice it to say that I know the images are identical as
1) I drew them to the screen
2) I captured them using the ScreenCapture function instead of using getRectCheckSum and then I used both the CompareBitmaps function and also the HashLib extension to check that the images captured were identical

Any ideas what I'm doing wrong? Surely these should both have exactly the same checksum?

Many thanks,

Ken

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jun 02, 2008 8:01 am

The checksum calculation includes the coordinates. So if your images are in different places they won't be the same.

Instead you could use ScreenCapture and CompareBitmaps. Or just FindImagePos might work for you (find the known image and see if it exists on the screen, and if so, how many instances and where are they).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

klcmay
Newbie
Posts: 16
Joined: Sun Jun 01, 2008 10:12 pm

Confused

Post by klcmay » Mon Jun 02, 2008 11:25 am

Thank you for your quick and helpful response.

I'm a little confused though as I've previously seen the exact same checksum being generated for a particular image regardless of where it is actually positioned on the screen. Has this perhaps changed in version 10? I will try to find my old code and run this on version 10.

In any case, I would have thought that the position would not be highly relevant for most users. Presumably (like me) they just want something like a MD5 hash of the pixels for comparison purposes. Collisions will be unlikely and you could always separately check the screen positions in the macro if this was important.

I am happy to use one of the other techniques that you suggested although I would have have thought that getRectChecksum would have had better performance than writing the screen image to disk with ScreenCapture and then having to compare this with another saved image. I will do some profiling of this.

Thanks again,

Ken

klcmay
Newbie
Posts: 16
Joined: Sun Jun 01, 2008 10:12 pm

Change in Version 10?

Post by klcmay » Tue Jun 03, 2008 9:58 pm

Further to my email above, I can now confirm:

Version 9.1.03 running on Windows XP Standard does not take the position of the image within the screen into account. The checksum is the same regardless of where the image is actually positioned - presumably some sort of algorithm working on the colours of each individual pixel within the rectangle.

Version 10.1.15 running on Vista creates different checksums for the same image if it is placed in a different part of the screen.

I am not sure if this is due to the difference in version or OS but I suspect it is the version of the software as I'm fairly sure I have seen the behaviour I expected on Vista too.

Obviously there is a discrepancy between the different behaviours. Personally, I would prefer the same checksum to be generated regardless of position but I can work around this using alternative methods I guess.

Any further thoughts?

Thanks,

Ken

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Wed Jun 04, 2008 10:01 pm

Have you tried image recognition?

Code: Select all

GetScreenRes>X,Y
ScreenCapture>0,0,X,Y,d:\screen.bmp
FindImagePos>d:\today_button.bmp,d:\screen.bmp,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Endif

 
In 9.2 (and above) this can be simplified to:

 
FindImagePos>d:\today_button.bmp,SCREEN,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Endif


Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts