private void SearchChampion() { TemplateMatchResult championSearchMatchResult = _searchFinder.FindTemplateIn(Image); Debug.Assert(championSearchMatchResult.IsMatch); Vector2 championSearchCenter = championSearchMatchResult.MatchArea.Center(); _gameWindowTyper.TypeAt((int)championSearchCenter.X, (int)championSearchCenter.Y, Champion); }
private void SetupSubImage(TemplateMatchResult templateMatchResult, Expression <Func <IImage, IImage> > subImageExpression) { Mock <IImage> subImageMock = new Mock <IImage>(); subImageMock.Setup(image => image.MatchTemplate(_templateMock.Object, It.IsInRange(0.75, 0.95, Range.Inclusive))) .Returns(templateMatchResult); _imageMock.Setup(subImageExpression) .Returns(subImageMock.Object); }
private void EnterLaneInChat() { TemplateMatchResult chatMatchResult = _chatFinder.FindTemplateIn(Image); Debug.Assert(chatMatchResult.IsMatch); Vector2 chatCenter = chatMatchResult.MatchArea.Center(); _gameWindowTyper.TypeAt((int)chatCenter.X, (int)chatCenter.Y, Lane); _gameWindowTyper.PressEnter(); }
/// <summary> /// Matches a template to the input text. Templates will automatically be preselected and than matched via key words. /// </summary> /// <param name="templates">All class templates that shall be compared</param> /// <param name="inputText"></param> /// <returns></returns> public TemplateMatchResult <DocumentClassTemplate> MatchTemplates(List <DocumentClassTemplate> templates, string inputText) { var retVal = new TemplateMatchResult <DocumentClassTemplate>(); var preselectedTemplates = templateMatcher.PreSelectTemplates(templates, inputText); if (preselectedTemplates.Count > 0) { retVal = templateMatcher.MatchTemplatesViaKeyWords(preselectedTemplates, inputText); } if (retVal.IsMatchSuccessfull == false) { retVal = templateMatcher.MatchTemplatesViaKeyWords(templates, inputText); } return(retVal); }
public ImageProcessingResult ProcessImage(IImage image) { TemplateMatchResult templateMatchResult = _templateFinder.FindTemplateIn(image); if (templateMatchResult.IsMatch) { Rectangle matchBorder = new Rectangle(templateMatchResult.MatchArea.Location, templateMatchResult.MatchArea.Size); matchBorder.Inflate(BorderMargin, BorderMargin); image.Draw(matchBorder); Image = image; TakeAction(templateMatchResult.MatchArea.Center()); return(new ImageProcessingResult(_gameStatus, image)); } return(ImageProcessingResult.Failed); }
/// <summary> /// Matches a template to the input text based on the template's key words. /// </summary> /// <param name="templates"></param> /// <param name="inputText"></param> /// <returns></returns> public TemplateMatchResult <T> MatchTemplatesViaKeyWords <T>(List <T> templates, string inputText) where T : DocumentBaseTemplate { var checkedWords = new Dictionary <string, int>(); var retVal = new TemplateMatchResult <T>(); inputText = Regex.Replace(inputText, " +", " "); foreach (var template in templates) { bool isMatchingTemplate = false; foreach (var keywordGroup in template.KeyWords) { var keyWordsInGroup = keywordGroup.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var doesAnyKeyWordInGroupMatch = CheckIfAnyKeyWordInKeyWordGroupMatches(keyWordsInGroup, inputText, checkedWords); if (doesAnyKeyWordInGroupMatch == true) { isMatchingTemplate = true; } else { isMatchingTemplate = false; break; } } if (isMatchingTemplate) { retVal.Template = template; retVal.IsMatchSuccessfull = true; break; } } return(retVal); }
private TemplateMatchResult SetupSubImageMatches(Vector2 targetLocation, float scale) { SetupImageSize(scale); int x = (int)(_imageMock.Object.Width * targetLocation.X); int y = (int)(_imageMock.Object.Height * targetLocation.Y); int width = _templateMock.Object.Width; int height = _templateMock.Object.Height; int subRegionMargin = (int)(MatchMargin * scale); int xOffset = x - subRegionMargin; int yOffset = y - subRegionMargin; Rectangle matchArea = new Rectangle(xOffset, yOffset, width + (2 * subRegionMargin), height + (2 * subRegionMargin)); TemplateMatchResult templateMatchResult = new TemplateMatchResult(new Rectangle(x, y, width, height)); SetupSubImage(templateMatchResult, matchArea); return(new TemplateMatchResult(new Rectangle(x + xOffset, y + yOffset, width, height))); }
private void SetupSubImage(TemplateMatchResult templateMatchResult, Rectangle matchArea) { SetupSubImage(templateMatchResult, image => image.SubImage(matchArea)); }
private void SetupSubImage(TemplateMatchResult templateMatchResult) { SetupSubImage(templateMatchResult, image => image.SubImage(It.IsAny <Rectangle>())); }