From 6f446dc1adcc734d177a7154780ea2b2fe960a94 Mon Sep 17 00:00:00 2001 From: MgAl2O4 <51430403+MgAl2O4@users.noreply.github.com> Date: Thu, 21 Jan 2021 21:09:33 -0500 Subject: [PATCH] more accurate detections for opened NM summoning --- SINoVision/ScannerCombatBase.cs | 20 +++++++++++--------- SINoVision/ScannerMessageBox.cs | 22 +--------------------- SINoVision/ScreenshotUtilities.cs | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/SINoVision/ScannerCombatBase.cs b/SINoVision/ScannerCombatBase.cs index b3c51a6..752955d 100644 --- a/SINoVision/ScannerCombatBase.cs +++ b/SINoVision/ScannerCombatBase.cs @@ -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) }; @@ -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(); @@ -163,13 +164,12 @@ 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) { @@ -177,7 +177,9 @@ protected void ScanSummonSelector(FastBitmapHSV bitmap, ScreenDataBase screenDat } 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); } } diff --git a/SINoVision/ScannerMessageBox.cs b/SINoVision/ScannerMessageBox.cs index 47b8c32..673f7e2 100644 --- a/SINoVision/ScannerMessageBox.cs +++ b/SINoVision/ScannerMessageBox.cs @@ -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 = diff --git a/SINoVision/ScreenshotUtilities.cs b/SINoVision/ScreenshotUtilities.cs index 41ab638..7438a7a 100644 --- a/SINoVision/ScreenshotUtilities.cs +++ b/SINoVision/ScreenshotUtilities.cs @@ -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;