public ImgMatchResult Match(Img searchImg, double threshold) { var source = MT; var search = searchImg.MT; var res = new Mat(); Cv2.MatchTemplate(source, search, res, TemplateMatchModes.CCoeffNormed); double minVal, maxVal; CvPoint minLoc, maxLoc; Cv2.MinMaxLoc(res, out minVal, out maxVal, out minLoc, out maxLoc); var r = new ImgMatchResult() { Threshold = threshold, Maxval = maxVal, Success = maxVal >= threshold, MatchedRect = new Rectangle(maxLoc.X, maxLoc.Y, search.Width, search.Height), }; if (r.Success && ConfigMgr.GetConfig().Debug) { source.SaveImage("source.png"); search.SaveImage("search.png"); Console.WriteLine(maxVal); //var combine = new Mat(new CvSize(source.Width, source.Height + search.Height), MatType.MakeType(source.Depth(), source.Channels())); //source.CopyTo(combine[new Range(0, source.Height), new Range(0, source.Width)]); //var xOff = (source.Width - search.Width) / 2; //search.CopyTo(combine[new Range(source.Height, source.Height + search.Height), new Range(xOff, search.Width + xOff)]); //Cv2.ImShow("combine", combine); //Cv2.Circle(source, maxLoc.X + search.Width / 2, maxLoc.Y + search.Height / 2, 25, Scalar.Red); //Cv2.ImShow("ImgMatch", source); } return(r); }
public static ConfigMgr GetInstance() { instance = instance ?? new JsonConfigMgr(); return(instance); }
public static void AddConfigItemsToMenuStrip(MenuStrip menuStrip) { var config = ConfigMgr.GetInstance().Config; menuStrip.SuspendLayout(); var settingItems = new ToolStripMenuItem(); settingItems.Text = "设置"; menuStrip.Items.Add(settingItems); var emulatorItems = new ToolStripMenuItem(); emulatorItems.Text = "模拟器: 未选择"; settingItems.DropDownItems.Add(emulatorItems); var emulatorMap = new Dictionary <string, Type>(); var refreshEmulatorCheckStatus = new Action(() => { foreach (ToolStripMenuItem item in emulatorItems.DropDownItems) { var emulatorType = emulatorMap.Get(item.Text); var bChecked = emulatorType == config.EmulatorType; item.Checked = bChecked; emulatorItems.Text = bChecked ? $"模拟器: {item.Text}" : emulatorItems.Text; } }); foreach (var emulatorType in Emulator.GetEmulatorTypes()) { var name = Emulator.GetInstanceByType(emulatorType).Name; var emulatorItem = new ToolStripMenuItem(); emulatorItem.Text = name; emulatorMap[name] = emulatorType; emulatorItems.DropDownItems.Add(emulatorItem); emulatorItem.Click += (s, e) => { config.EmulatorType = emulatorType; ConfigMgr.GetInstance().SaveConfig(); refreshEmulatorCheckStatus(); EventMgr.FireEvent(EventKeys.ConfigEmulatorTypeChanged); }; } refreshEmulatorCheckStatus(); var regionItems = new ToolStripMenuItem(); regionItems.Text = "区域"; settingItems.DropDownItems.Add(regionItems); var refreshRegionCheckStatus = new Action(() => { foreach (ToolStripMenuItem item in regionItems.DropDownItems) { var bChecked = item.Text == config.Region.ToString(); item.Checked = bChecked; regionItems.Text = bChecked ? $"区域: {item.Text}" : regionItems.Text; } }); foreach (var name in Enum.GetNames(typeof(Region))) { var regionItem = new ToolStripMenuItem(); regionItem.Text = name; regionItems.DropDownItems.Add(regionItem); regionItem.Click += (s, e) => { config.Region = (Region)Enum.Parse(typeof(Region), regionItem.Text); ConfigMgr.GetInstance().SaveConfig(); refreshRegionCheckStatus(); EventMgr.FireEvent(EventKeys.ConfigRegionChanged); }; } refreshRegionCheckStatus(); #if DEBUG var openDirItem = new ToolStripMenuItem(); openDirItem.Text = "打开工作目录"; menuStrip.Items.Add(openDirItem); openDirItem.Click += (s, e) => { Utils.OpenDirectoryInExplorer(Environment.CurrentDirectory); }; #endif menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); }