FindImagePos exact match

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

FindImagePos exact match

Post by gdyvig » Tue Aug 25, 2009 2:44 pm

Please allow FindImagePos to compare every pixel in the needle file when FIP_SCANPIXELS=0. This is required for precision matches.

Precision matches are not required to find images, but to be assured the correct image is found - to avoid false finds. This would be used in situations where accuracy is more important than performance.

It was discovered that setting FIP_SCANPIXELS to a value equal to or greater than the number of pixels in a needle file does not result in an exhaustive compare in this thread started by observer:

http://www.mjtnet.com/usergroup/viewtopic.php?t=5665

Experimentation showed that FIP_SCANPIXELS is not the total number of pixels compared, but the number of random searches performed to select pixels to compare. As more pixels are selected the more difficult it is to randomly find an unselected pixel.

Experimentation also showed that setting FIP_SCANPIXELS to extremely large values does not increase the number of selected pixels. As a result it is impossible to compare every pixel in the needle file.

Scenarioes where exact match is required:
1. Script must distinguish between two icons differing by only 1 or 2 pixels. This will result in a false find 1 to 20 percent of the time.
2. Script must distinguish one icon from large numbers of very similar icons. This will result in a false find 20-99 percent of the time.
3. Script running a very large number of times must distinguish one icon from other similar icons will fail a significant percentage of the time.


Thanks,

Gale

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 26, 2009 10:29 pm

If you have a situation where you need to match 100% (every single pixel matches exactly). You might try this.

- Your needle file MUST be a BMP file created either using the ScreenCapture> function or by using the editor's "Image Capture Tool".

- You must know the image size in pixels of the needle file and use that exact size to set the variables "NeedleX" and "NeedleY".

This script will find every instance of the needle file on the screen then use DOS comp (compare) to test the created files against the needle image file to see if they happen to be exactly the same file. In the situation where the needle image and the found screen image are exactly the same image, their image files will match exactly as well.

I did not notice any performance degradation over a simple FindImagePosition> with the color tolerance set to 10.

Code: Select all

Let>NeedleX=60
Let>NeedleY=55
FindImagePos>%temp_dir%FIP_Test.bmp,SCREEN,10,0,X_pos,Y_pos,Num_Found

If>Num_Found>0
  Let>kk=0
  Let>Good_Locations=
  Repeat>kk
    Let>SC_ULX=X_pos_%kk%
    Let>SC_ULY=Y_pos_%kk%
    Let>SC_LRX=%SC_ULX%+%NeedleX%
    Let>SC_LRY=%SC_ULY%+%NeedleY%
    ScreenCapture>SC_ULX,SC_ULY,SC_LRX,SC_LRY,%temp_dir%FIP_Test_2.bmp
    Let>RP_WAIT=1
    Let>RP_WINDOWMODE=0
    Run>cmd /c echo n | comp %temp_dir%FIP_Test.bmp %temp_dir%FIP_Test_2.bmp > %temp_dir%FIP_compare.txt
    ReadFile>%temp_dir%FIP_compare.txt,TestRes
    Separate>TestRes,Files compare OK,test
    If>test_count>1
      Let>Good_Locations=%Good_Locations%%SC_ULX%,%SC_ULY%%CRLF%
    EndIf
    Add>kk,1
  Until>kk,%Num_Found%
EndIf

MDL>Good_Locations

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

workaround requires color tolerance=0

Post by gdyvig » Thu Aug 27, 2009 4:52 am

Hi JRL,

It is good to know there is a good workaround. But as you say it only works for exact matches. While setting the color tolerance > 0 works in your example it means some of the pixel-for-pixel matches will fail the DOS filecompare test. So you would normally set color tolerance=0 so you would not have so many images to compare.

If you DO want a compare that considers every pixel but with a color tolerance you would need the enhancement or an even better workaround.

If the enhancement can be done without too much effort I think it should be done when the opportunity arises.

If the enhancement is not done the user guide should explain that FIP_SCANPIXELS is usually somewhat less than the actual number of pixels compared due to the laws of probability.

The guide should also explain that making FIP_SCANPIXELS greater than the size of the needlefile does not improve accuracy. This is probably because the algorithm attempts to avoid excessive compares where FIP_SCANPIXELS is orders of magnitude larger than the needle file.

Gale

observer
Junior Coder
Posts: 44
Joined: Tue Aug 18, 2009 7:55 pm

Post by observer » Thu Aug 27, 2009 1:19 pm

Hello!
JRL
You had made a good try. But as gdyvig noticed
If the enhancement can be done without too much effort I think it should be done when the opportunity arises
There is no need to use Dos Compare command as we have got MacroScheduler's GetRectCheckSum> command and there is no problem to find out the CheckSum of the Needle-Image (not the checksum of the Needle-Image file).
Best regards.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Aug 27, 2009 2:34 pm

Gale and observer,

I always hesitate to post "work arounds" when someone has made a request for an enhancement. I'm always afraid that the work around will be perceived as a legitimate answer and that the enhancement request is not needed. As I stated, this could only function in the situation where every single pixel matches. There is no fudge factor like the FindImagePos> function provides. This thought was not intended to be a fix only a possible short term solution in the event that the enhancement is not implemented overnight.

observer,

Thanks for the suggestion about using GetRectCheckSum> rather than DOS comp. I've never used the function and didn't think about the possibility of using it.

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