SRL Archive - SRL Snippets

Color testing tool


bonsai

2013-11-03 11:33:37

I thought I would post this little script I've been using to help me fine tune color choices and the size of the boxes to choose for finding.

It's just a copy of the mainscreen.findObject function with some drawing and print statements. When you run it it will show the TPA of the colors it found, display the boxes made from splitting the TPA and print out some details about how many colors are in each box. It also prints the mouseovertextcount values to assist with using things while mouseovertext is broken. You can use the presented data to adjust the box sizes, etc, and fine tune your choices.

You run it while logged in and located in the area you are trying to find objects in. Just edit the values at the top and run the script. It will paint on the screen and print to the debug box.

Script:

program testColors;
{$DEFINE SMART}
{$include_once srl-6/srl.simba}
{$f-}

const
color2test = 12097925;
tolerance = 4;
hue = 0.09;
sat = 0.88;
w = 50;
h = 50;
matchCount = 1000;

var
x, y : integer;

// modifed from mainscreen.simba to do debugging and print mouseovertextcounts
function __findObject(var ix, iy: integer; cols, tols: TIntegerArray; colSettings: TColorSettings;
sortFrom: TPoint; objWidth, objHeight, minCount: integer;
mouseOverTextCounts: TIntegerArray; searchBox: TBox; mouseAction: integer = MOUSE_NONE): boolean;
var
i, l: integer;
myPoint: TPoint;
aPoints: T2DPointArray;
ATPA: T2DPointArray;
TPA: TPointArray;
cs: TColorSettings;
pixelCount : integer;
begin
result := false;

cs.retrieve();
colSettings.apply();
l := length(cols);

setLength(ATPA, l);

for i := 0 to (l - 1) do
findColorsSpiralTolerance(ix, iy, ATPA[i], cols[i], searchBox, tols[i], colSettings);

cs.apply();

TPA := ATPA.merge();
if (length(TPA) <= 0) then
begin
writeln('No colors found');
exit(false);
end;

writeln('Colors found: '+toStr(length(TPA)));
smartImage.debugTPA(TPA);

aPoints := TPA.toATPA(objWidth, objHeight);
for x := 0 to high(aPoints) do
writeln('Length of aPoints[', x, '] = ', length(aPoints[x]));
aPoints.filterBetween(0, minCount); // removes objects that don't have enough colors
writeln('Possible objects found: '+toStr(length(aPoints)));
smartImage.debugATPA(aPoints);
takeScreenshot(toStr(getSystemTime()) + '.png');

aPoints.sortFromFirstPoint(sortFrom);
for x := 0 to high(aPoints) do
writeln('Length of filtrered aPoints[', x, '] = ', length(aPoints[x]));

// loop through each possible object
for i := 0 to high(aPoints) do
begin
myPoint := aPoints[i].getMiddle();
mouse(myPoint, MOUSE_MOVE);
pixelCount := getMouseOverTextCount();
writeln('Length of points[', i, ']=', length(aPoints[i]), ' mouseOverTextCount = ', pixelCount);
end;
end;

begin
ClearDebug();
smartEnableDrawing := true;
SetupSRL();

__findObject(x, y, [color2test], [tolerance], colorSetting(2, hue, sat),
point(200,200), w, h, matchCount, [2], mainscreen.getBounds(), MOUSE_NONE);
end.

Kasi

2013-11-03 12:46:13

Cool, you should look at Auto Color Aid.

bonsai

2013-11-03 14:52:45

Sure, I use ACA to do the color selection. But it doesn't help with width/height and minimum number of colors in the matched boxes.

After doing the ACA work I use this scriptlet to try it out live and refine the width/height for the boxing and select good numbers for the minimum match count. If you choose bad numbers for these you end up with missed objects, false positives, multiple hits on one object, etc.

By playing with it you can come up with a sweet spot that returns quality matches.