From c03a8011c26b37f38dd1a3299ca1abcab5c11fda Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 21 Oct 2024 04:16:46 +0900 Subject: [PATCH] Update ScreenMatch.cs --- .../WelsonJS.Service/ScreenMatch.cs | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs index 0b59ab1..472e647 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ScreenMatch.cs @@ -109,7 +109,7 @@ public class ScreenMatch private string templateDirectoryPath; private string outputDirectoryPath; private int templateCurrentIndex = 0; - private double threshold = 0.4; + private double threshold = 0.3; private string mode; private bool busy; private List _params = new List(); @@ -181,8 +181,8 @@ public class ScreenMatch sampleNodup = new List(); sampleNodupSize = new Size { - Width = 256, - Height = 32 + Width = 180, + Height = 60 }; outdatedSamples = new Queue(); @@ -249,6 +249,13 @@ public class ScreenMatch break; } + case "threshold": + { + double.TryParse(config_value, out double t); + threshold = t; + break; + } + case "sample_clipboard": { sampleClipboard = new List(config_value.Split(':')); @@ -277,6 +284,20 @@ public class ScreenMatch break; } + case "sample_nodup_width": + { + int.TryParse(config_value, out int w); + sampleNodupSize.Width = w; + break; + } + + case "sample_nodup_height": + { + int.TryParse(config_value, out int h); + sampleNodupSize.Height = h; + break; + } + case "sample_adjust_x": { int.TryParse(config_value, out sampleAdjustX); @@ -465,24 +486,20 @@ public class ScreenMatch // If the index value is negative, retrieve and use an outdated image from the queue if (nextTemplateInfo.Index < 0) { - parent.Log($"Review and find the last data of {nextTemplateInfo.FileName}..."); - Bitmap outdatedImage = null; - // Dequeue the oldest image from the sampleOutdated queue + parent.Log($"Finding a previous screen of {nextTemplateInfo.FileName}..."); + try { while (outdatedSamples.Count > 0) { outdatedImage = outdatedSamples.Dequeue(); - if (outdatedImage.Tag != null) { - parent.Log($"Reviewing... {((SampleInfo)outdatedImage.Tag).FileName}"); - if (((SampleInfo)outdatedImage.Tag).FileName == nextTemplateInfo.FileName) { - parent.Log($"Found the last data of {nextTemplateInfo.FileName}"); + parent.Log($"Found the previous screen of {nextTemplateInfo.FileName}"); break; } } @@ -490,15 +507,26 @@ public class ScreenMatch } catch (Exception ex) { - parent.Log($"Error while reviewing the data: {ex.Message}"); + parent.Log($"Error finding a previous screen: {ex.Message}"); } + outdatedImage.Save("outdated.png"); + // Find the matching positions of the outdated image in the main image if (outdatedImage != null) { - matchPositions = FindTemplate(out_mainImage, (Bitmap)outdatedImage.Clone()); + matchPositions = FindTemplate(out_mainImage, outdatedImage); + if (matchPositions.Count > 0) + { + parent.Log("Match found with the outdated image"); + } + else + { + parent.Log("No match found with the outdated image"); + } } else { + parent.Log("Not found a outdated image"); matchPositions = new List(); } }