Tolerance Tester

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Tolerance Tester

Post by Phil Pendlebury » Mon Jan 18, 2010 8:20 pm

Greetings all,

I have been using this for a while and it occurred to me today that I could finish it off so that others may find it useful.

It's a little tool to test for colour tolerance.

It's a tool you may find useful but you will have to read the following explanation to see if it is for you.

Over the last couple of years I have found that with my main application some users have problems with the screen recognition part of the application. Usually this is because the buttons that my application looks for are slightly different to the ones I originally included.

I have built in to my application methods for adjusting colour tolerance and also for the user to take their own screen shots which I will then edit for them and send them back their exact buttons.

Even so, many users don't bother to do this and they write to me for help.

I have also built into my application a routine that automatically zips up a copy of the user's screen and the button it was looking for. I then look at that and see if I can tell why the button has not been found.

Often, it is down to tolerance. Sometimes it is a small offset and sometimes large.

I started work on adding a loop into my main application that adjusts tolerance upwards depending on if it finds the button or not. As you can imagine this is slightly problematic due to the number of different buttons to look for etc.

So I use this application to check the file that the user sends me.

What it does:
  • It will allow you to select a needle and haystack file
    It will then check the haystack for the needle with a colour tolerance of 1 (exact perfect match).
    If the needle is not found it will then add 1 to the tolerance and try again until it finds the needle or until the max tolerance (255) is reached.

    It keeps a log of all relevant data (optionally).
    It will also allow you to search for more than the 1st match (i.e. set a value of 3 and the script will stop when it has found 3 of the needles).
If anyone thinks they may find it useful I have uploaded it here:

http://www.pendlebury.biz/applications/

Contained in this zip file are:
  • The script folder
    A compiled exe file version of the script in case you cannot compile.
    The script (scp) file in case you want to look at it (I will also post it below this with some screen shots).
I hope this may be of help to some of you.

If anyone would like to add anything to make this more useful you would be more than welcome. Please share your additions.

Also if anyone can find fault with my scripting you are also welcome to share that. There are some things that may look a bit odd but usually there is a reason for them.

Cheers,

Phil.

PS. If Marcus thinks this may be useful feel free to sticky. :-)
Last edited by Phil Pendlebury on Fri Feb 26, 2010 2:20 pm, edited 1 time in total.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Jan 18, 2010 8:37 pm

Here's a screen shot:

Image
Last edited by Phil Pendlebury on Mon Mar 01, 2010 4:35 pm, edited 1 time in total.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Jan 18, 2010 8:41 pm

Code: Select all

Let>RP_ADMIN=1
Let>APP_TITLE=Phil's Tolerance Test
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>MSG_WIDTH=360
Let>MSG_HEIGHT=200
Let>WF_TYPE=1
Let>VAREXPLICIT=0
Let>CF_OVERWRITE=1

Let>OutputFileName=tolerancetest.txt


Dialog>CTDialog
   Caption=Tolerance Test
   Width=408
   Height=254
   Top=CENTER
   Left=CENTER
   Max=0
   Min=0
   Close=0
   Resize=0
   Edit=msEdit1,8,48,297,Needle
   Edit=msEdit2,8,80,297,Haystack
   Edit=msEdit3,8,174,25,1
   Edit=msEdit4,8,148,25,60
   CheckBox=msCheckBox1,Add to txt log,8,200,98,True
   Button=Needle,312,48,81,22,0
   Button=Haystack,312,80,81,22,0
   Button=Use Screen,312,112,81,22,10
   Button=TEST!,312,144,81,73,2
   Button=QUIT,216,144,81,73,4
   Label=Colour Tolerance Tester for Macro Scheduler by Phil Pendlebury,8,8,true
   Label=Use screen shot as Haystack (after 5 seconds):,80,118,true
   Edit=msEdit4,8,145,25,70
   Label=Find number of needles,40,178,true
   Label=Tolerance Limit,40,152,true
   FileBrowse=Needle,msEdit1,,open
   FileBrowse=Haystack,msEdit2,,open
EndDialog>CTDialog

Show>CTDialog
Label>DialogLoop
  GetDialogAction>CTDialog,res
  IF>res=2,doitnow
  IF>res=4,Quit
  IF>res=10
    GetScreenRes>scxarr,scyarr
    Wait>5
    ScreenCapture>0,0,%scxarr%,%scyarr%,%SCRIPT_DIR%\ttcapture.bmp
    Let>CTDialog.msEdit2=%SCRIPT_DIR%\ttcapture.bmp
    RDA>CTDialog
    MDL>Screen Capture Done. OK to continue.
  ENDIF
  //
  Let>NFile=%CTDialog.msEdit1%
  Let>HFile=%CTDialog.msEdit2%
  Let>NNeedles=%CTDialog.msEdit3%
  Let>TLimit=%CTDialog.msEdit4%
  Let>addtotext=%CTDialog.msCheckBox1%
  //
  Wait>0.001
GOTO>DialogLoop

Label>doitnow
IF>{(%NFile%="Needle") OR (%HFile%="Haystack")}
  MDL>You need to pick a Needle and Haystack file
  RDA>CTDialog
  GOTO>DialogLoop
ENDIF
CloseDialog>CTDialog
//
GetDate>date
GetTime>time
//
Let>test_found=0
Let>loop=0
Let>tolerance=1
Repeat>loop
  IF>tolerance>%TLimit%,Exit
  FindImagePos>%NFile%,%HFile%,%tolerance%,1,arrXarr,arrYarr,test_found
  IF>test_found=%NNeedles%,Found
  IF>test_found>%NNeedles%,Found
  Msg>Needle: %NFile%%CRLF%Haystack: %HFile%%CRLF%%CRLF%Tolerance = %tolerance%%CRLF%Found = %test_found%
  Let>tolerance=tolerance+1
  Let>loop=loop+1
Until>loop=%TLimit%
GOTO>Exit

Label>Found
IF>addtotext=True
  WriteLn>%SCRIPT_DIR%/%OutputFileName%,,%date% %time%%CRLF%Needle = %NFile%%CRLF%Haystack = %HFile%%CRLF%Tolerance = %tolerance%%CRLF%Found = %test_found%%CRLF%X Position = %arrXarr_0%%CRLF%Y Position = %arrYarr_0%%CRLF%
ENDIF
MessageModal>%tolerance% = Tolerance required to find this needle.%CRLF%%test_found% = Number of needles found.%CRLF%%arrXarr_0% = Needle X Position.%CRLF%%arrYarr_0% = Needle Y Position.
GOTO>Quit

Label>Exit
IF>addtotext=True
  WriteLn>%SCRIPT_DIR%/%OutputFileName%,,%date% %time%%CRLF%Needle = %NFile%%CRLF%Haystack = %HFile%%CRLF%Found no matches at tolerance limit of %TLimit%
ENDIF
MDL>Sorry there were no matches for your file:%CRLF%%NFile%%CRLF%at this tolerance limit.

Label>Quit
Last edited by Phil Pendlebury on Mon Mar 01, 2010 6:01 pm, edited 1 time in total.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Mar 01, 2010 5:59 pm

Updated this today with a few fixes, enhancements (see screen shot) and some error catching.

There was also a daft error in the original loop that would sometimes cause the script not to work at all. :oops:

Also fixed.

:-)
Phil Pendlebury - Linktree

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