Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
more accurate detections for opened NM summoning
Browse files Browse the repository at this point in the history
  • Loading branch information
MgAl2O4 committed Jan 22, 2021
1 parent f213ee5 commit 6f446dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
20 changes: 11 additions & 9 deletions SINoVision/ScannerCombatBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public override string ToString()
protected Rectangle rectBoostSearch = new Rectangle(1, -2, 13, 24);
protected Rectangle[] rectActionElements = new Rectangle[] { new Rectangle(3, 3, 28, 2), new Rectangle(35, 47, 14, 2), new Rectangle(47, 36, 2, 10) };
protected Rectangle rectBigButton = new Rectangle(103, 506, 131, 44);
protected Rectangle rectSummonSelector = new Rectangle(13, 466, 15, 5);
protected Rectangle rectSummonSelectorA = new Rectangle(10, 466, 60, 5);
protected Rectangle rectSummonSelectorB = new Rectangle(19, 474, 9, 9);
protected Point[] posBigButton = new Point[] { new Point(106, 506), new Point(170, 506), new Point(230, 506), new Point(106, 551), new Point(170, 551), new Point(230, 551) };
protected Point[] posBoostIn = new Point[] { new Point(7, 5), new Point(7, 8), new Point(7, 11), new Point(7, 17), new Point(10, 8) };
protected Point[] posBoostOut = new Point[] { new Point(6, 14), new Point(8, 14), new Point(10, 11), new Point(12, 11) };
Expand All @@ -89,7 +90,7 @@ public override string ToString()
private FastPixelMatch matchBoostOut = new FastPixelMatchHSV(-40, 30, 0, 100, 0, 40);
private FastPixelMatch matchBoostInW = new FastPixelMatchMono(220, 255);
private FastPixelMatch matchSummonIcon = new FastPixelMatchMono(180, 255);
private FastPixelMatch matchSummonBack = new FastPixelMatchHSV(10, 40, 0, 100, 0, 100);
private FastPixelMatch matchSummonBack = new FastPixelMatchHSV(15, 25, 40, 60, 20, 30);

protected MLClassifierWeaponType classifierWeapon = new MLClassifierWeaponType();

Expand Down Expand Up @@ -163,21 +164,22 @@ protected void ScanSP(FastBitmapHSV bitmap, ScreenDataBase screenData)

protected void ScanSummonSelector(FastBitmapHSV bitmap, ScreenDataBase screenData)
{
float fillPctB = ScreenshotUtilities.CountFillPct(bitmap, rectSummonSelector, matchSummonBack);
bool hasFillB = (fillPctB > 0.95f);
var avgPx = ScreenshotUtilities.GetAverageColor(bitmap, rectSummonSelectorA);
var iconFillPct = ScreenshotUtilities.CountFillPct(bitmap, rectSummonSelectorB, matchSummonIcon);
var isAvgMatching = matchSummonBack.IsMatching(avgPx);
var isIconMatching = (iconFillPct > 0.15f) && (iconFillPct < 0.35f);

float fillPctF = !hasFillB ? 10.0f :
ScreenshotUtilities.CountFillPct(bitmap, rectSummonSelector, matchSummonIcon);

screenData.hasSummonSelection = hasFillB && (fillPctF < 0.3f);
screenData.hasSummonSelection = isAvgMatching && isIconMatching;

if (DebugLevel >= EDebugLevel.Simple)
{
Console.WriteLine("{0} ScanSummonSelector: {1}", ScannerName, screenData.hasSummonSelection);
}
if (DebugLevel >= EDebugLevel.Verbose)
{
Console.WriteLine(" fillPctF: {0}, fillPctB: {1}", fillPctF, fillPctB);
Console.WriteLine(" avgPx: ({0}) vs ({1}) => {2}, fillIcon: {3} => {4}",
avgPx, matchSummonBack, isAvgMatching,
iconFillPct, isIconMatching);
}
}

Expand Down
22 changes: 1 addition & 21 deletions SINoVision/ScannerMessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,32 +145,12 @@ public override Rectangle GetSpecialActionBox(int actionType)
return Rectangle.Empty;
}

protected FastPixelHSV GetAverageColor(FastBitmapHSV bitmap, Rectangle bounds)
{
float hueAcc = 0.0f;
float satAcc = 0.0f;
float valAcc = 0.0f;
float scale = 1.0f / bounds.Width;

for (int idx = 0; idx < bounds.Width; idx++)
{
FastPixelHSV testPx = bitmap.GetPixel(bounds.X + idx, bounds.Y);
hueAcc += testPx.GetHue();
satAcc += testPx.GetSaturation();
valAcc += testPx.GetValue();
}

FastPixelHSV avgPx = new FastPixelHSV();
avgPx.SetHSV((int)(hueAcc * scale), (int)(satAcc * scale), (int)(valAcc * scale));
return avgPx;
}

protected bool HasOkButtonArea(FastBitmapHSV bitmap, ScreenData screenData)
{
FastPixelHSV[] avgPx = new FastPixelHSV[rectButtonPos.Length];
for (int idx = 1; idx < avgPx.Length; idx++)
{
avgPx[idx] = GetAverageColor(bitmap, rectButtonPos[idx]);
avgPx[idx] = ScreenshotUtilities.GetAverageColor(bitmap, rectButtonPos[idx]);

var scanOb = new ActionData();
scanOb.buttonColor =
Expand Down
20 changes: 20 additions & 0 deletions SINoVision/ScreenshotUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,26 @@ public static float CountFillPct(FastBitmapHSV bitmap, Rectangle box, FastPixelM
return (float)matchPixels / totalPixels;
}

public static FastPixelHSV GetAverageColor(FastBitmapHSV bitmap, Rectangle bounds)
{
float hueAcc = 0.0f;
float satAcc = 0.0f;
float valAcc = 0.0f;
float scale = 1.0f / bounds.Width;

for (int idx = 0; idx < bounds.Width; idx++)
{
FastPixelHSV testPx = bitmap.GetPixel(bounds.X + idx, bounds.Y);
hueAcc += testPx.GetHue();
satAcc += testPx.GetSaturation();
valAcc += testPx.GetValue();
}

FastPixelHSV avgPx = new FastPixelHSV();
avgPx.SetHSV((int)(hueAcc * scale), (int)(satAcc * scale), (int)(valAcc * scale));
return avgPx;
}

public static void FindColorRange(FastBitmapHSV bitmap, Rectangle box, out int minMono, out int maxMono)
{
minMono = 255;
Expand Down

0 comments on commit 6f446dc

Please sign in to comment.