Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Pattern-Recognition >

Image/Pixel-Color Operations

ANA.FindPattern4 - Find 4 Patterns

Previous Top Next


MiniRobotLanguage (MRL)

 

ANA.FindPattern4

Locate any of4 specified Pattern-Objects in an Target Image-Register (IR)

 

 

Intention

 

I could have named this Command: "Find Alternative Pattern". It will take four Patterns as Parameter and find either of these.

They can, but they must not have the same size. Each Pattern also has its own values for Color-Tolerance and Minimum Pixel-Hits.

 

This command will find the Locations where either of these four specified Patterns are in an Image.

You must  load the Target-Picture into IR 0 and load the four Patterns into IR 1, IR 2, IR 3, and IR 4.

 

For more  Details please see the

ANA.FindPattern Command

 

 

1. Capture Screenshot of Brave-Browser and use it for Pattern-Search

We will search for 4 Patterns at the same time.

 

STW.ct|Chrome_WidgetWin_1|General Discussion - Brave

SWP.12,9|1216,717|T

FOR.$$LR3|1|4

  CAL.$$NUM=$$LR3+8

  VAR.$$PA1=?pattern\Cross_$$NUM.bmp

  ANA.Load|$$LR3|$$PA1

  DBP.Loading: $$PA1

NEX.

VAN.$$COT=110

' Prefixing the Pixelhits with a "-" Sign makes it use the percentage

' Here we use 50% of the total possible Pixel-Hits

VAN.$$PIH=-60

ANA.Snap|0

ANA.FindPattern4|0|$$COT|$$PIH|$$COT|$$PIH|$$COT|$$PIH|$$COT|$$PIH

DMP.6

ANA.ShowHits|0!

ENR.

 

clip0022

 

 

Important Notice: 

Please check the ANA.FindPattern-Command to see details on how to use this command.

There you will find important Information about "Mouseover-Effects" and "Admin-Rights".

 

 

 

Syntax

 

ANA.FindPattern4[|P1][|P2][|P3][|P4][|P5][|P6][|P7]

 

Parameter Explanation

 

P1 - opt. Target IT Image-Register number for Target, if omitted, IR 0 will be used. The Patterns to search for will always be in IR 1 and all following.

P2 - opt. Color Tolerance A, if omitted 0 will be used.

P3 - opt. Pixel-Hit Tolerance A, This value depends on the Pattern that you feed into the Command.

     If your Pattern is 8x8 then the maximum number of Pixels that could match is 64. If its 24x8 the maximum Number is 192.

     If you specify a negative number like "-85" then this is treated as a Percentage of the total Pixel-Number, means "85% of the maximum Pixels of that Pattern"

     If omitted or 0 the default value will be 85% of Pixel-Number in Pattern.

P4 - opt. Color Tolerance B, see P2.

P5 - opt. Pixel-Hit Tolerance B,see P3.

P6 - opt. Color Tolerance C, see P2.

P7 - opt. Pixel-Hit Tolerance C,see P3.

P8 - opt. Color Tolerance D, see P2.

P9 - opt. Pixel-Hit Tolerance D,see P3.

P10 - opt. 0/1 - Debug-Flag

 

About the P9 - Parameter ("Pixel-Hits"):

The maximum number of matching pixels in your pattern is determined by its size.

For example, an 8x8 pattern can have up to 64 matching pixels, whereas a 24x8 pattern can have up to 192.

P9 is based on the total number of pixels in the pattern.

If you set it to 63, for instance, it means that at least 63 pixels must match the pattern, including the tolerance.

If you input a negative number for P9, such as "-15", it's treated as a percentage of the total pixel count, translating to "15% of the maximum pixels of that pattern".

If you leave it empty or set it to 0, the default value will be 85% of the pixel count in the pattern.

P9 denotes the minimum number of matches needed to accept a result.

Be careful not to set P9 too low, as it could potentially overwhelm the system with a massive number of results.

 

This command has some special features regarding the "Pixel-Hit Tolerance Parameters".

1.If you specify "0", the command will calculate the maximum possible number of hits for the loaded pattern and take 85% of that value.

2.If you specify a negative value like "-69", the command will also calculate the maximum possible number of hits for the loaded pattern and take that as 100%. In this example, it would be 69%, so if this is a 12x12 pattern and therefore has a maximum of 144 pixel-hits, 69% of that would be 99 pixels.

3.You can directly specify a positive value that is the exact number of needed pattern-pixels for the pattern to be considered as found.

4.The maximum number of found results is limited by the setting of "MaxResults" using the ANA.SetData command.

5.Due to the use of multiple CPU cores at different places at the same time, there is no guarantee in which order matches are returned.

6.The command will leave a 0/1 on the TOS. As always, a 0 means error, while a 1 means "all fine". For example, if one of the IR's does not exist, then you will get a result "0" on TOS. The program will not generate an error message.

 

The command leaves a 0/1 on the TOS. Consistently, 0 signifies an error, while 1 indicates that everything is fine.

For instance, if one of the IR's doesn't exist, you'll receive a "0" on the TOS.

The program won't generate an error message in this case.

 

About the P10 - Parameter ("Debug Flag"):

The Flag-Parameter meanwhile can do a lot more then just help Debugging.

 

1 - Enable Debug-Output in Console Window

2 - Snap last used Window again if not found

4 - Use "Difference Map Search"

8 - Disable Filtering (if set)

16 - Use "Invert Pattern"

32 - Use "Complement Pattern"

64 - Use "Extended Search" (takes longer, makes more evaluations)

 

 

The results of the Operation can be accessed with the "ANA.gres" Command.

 

 

Example

 

 

Capture Screenshot of complete Desktop and use it for Pattern-Search

This will include all Screens on a Dual-Screen System. Here we search a Pattern on the complete Desktop.

 

'***********************************

' ANA.FindPattern-Sample

'

'***********************************

STW.ct|Progman|Program Manager

' We Snapshot the Desktop into IR 0

ANA.Snap|0

 

' This are the Pattern we search for

$$PAA=?path\Help12.bmp

$$PAB=?path\Help9.bmp

' We load the Pattern into IR 1+2

ANA.Load|1|$$PAA

ANA.Load|2|$$PAB

 

' This is the Pattern Searching Command, 

' Due to the value "1" as last Parameter, we will get a Debugprint 

' of all found Hits. The displayed Point is in the Center of the Pattern. 

' Note that we use a different Numbers for the Pixel-Hits because the second Pattern is smaller ( 9x9=81 Pixel)

ANA.fpa2|0|1|0|125|0|74|1

' This command will put the results of the search on to the Stack.

' Number of found Patterns is on TOS

POP.$$POA

MBX. We got $$POA Results

' We do not need first 3 Found Pattern so we remove them from Stack

STJ.Remo|0|1|2

' This is the Pattern we drive to

POP.$$POA

MMV.t|$$POA

MBX.!

ENR.

 

 

 

Remarks

Speed Considerations:

1. The Command is "Multithreaded" and works best with a Multicore CPU.

2. The Command will need a lot of CPU-Power, it may also use the GPU at some point internally.

3. Generally the Command is very fast even in very large windows, as long as the Computer has a modern CPU.

4. The larger the Pattern, the slower the process.

5. Currently it may speed up the process, if you have the pattern touch the upper left corner. This may change in the future.

6. If a Pattern is very slow, just record another Pattern. And try this again.

7. A pattern that is completely empty will not work as there is nothing to recognize in it.

 

Do not use ".jpg" Images or images that are compressed with Artefacts. Generally use ".bmp" or ".png" Images. Otherwise the result will be hard to predict.

 

Limitations:

Choosing wrong values for P3,P4 and P5,P6 may overrun the robot with too many "fitting results" and may keep the system busy for minutes.

We did not yet implement an "Maximum number of results" at this time.

 

The resolution of the Pattern-Images that can be used is limited to those resolutions that can be saved with the "Human Eye-Recorder"-Tool.

 

 

See also:

 

    ANA_FindPattern