private void ProcessCommunityCardActions(Bitmap screenshot) { /* If community cards are supported, try to match them */ if (colorMap.SupportsCommunityCards) { List <Bitmap> communityCardImages = new List <Bitmap>(); ArrayList communityCardsActions = colorMap.GetCommunityCardsActions(); foreach (String action in communityCardsActions) { Rectangle actionRect = recognitionMap.GetRectangleFor(action); if (!actionRect.Equals(Rectangle.Empty)) { communityCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect)); } else { Globals.Director.WriteDebug("Warning: could not find a rectangle for action " + action); } } // We try to identify as many cards as possible CardList communityCards = matcher.MatchCards(communityCardImages, true, communityCardsActions, table.MatchHistogramThreshold(), table.MatchTemplateThreshold(), table.AllowableMatchTemplateThreshold() ); if (communityCards != null && communityCards.Count > 0) { //Globals.Director.WriteDebug("~~~ Matched board cards! " + communityCards.ToString()); handler.BoardRecognized(communityCards); } else { Globals.Director.WriteDebug("~~~ Warning: could not find a commnity cards "); } // Dispose foreach (Bitmap image in communityCardImages) { if (image != null) { image.Dispose(); } } } }
void timedScreenshotTaker_ScreenshotTaken(Bitmap screenshot) { UpdateCardMatchDialogSpawnLocation(); /* This code would resize the map and recompute the data in it, * but we don't use this approach anymore. */ //recognitionMap.AdjustToSize(screenshot.Size); /* Instead if the screenshot we took differs in size from the map at our disposal * we resize the window and retake the screenshot */ if (!screenshot.Size.Equals(recognitionMap.OriginalMapSize)) { Trace.WriteLine(String.Format("Screenshot size ({0}x{1}) differs from our map image ({2}x{3}), resizing window...", screenshot.Size.Width, screenshot.Size.Height, recognitionMap.OriginalMapSize.Width, recognitionMap.OriginalMapSize.Height)); Size winSize = tableWindow.Size; Size difference = new Size(screenshot.Size.Width - recognitionMap.OriginalMapSize.Width, screenshot.Size.Height - recognitionMap.OriginalMapSize.Height); Size newSize = winSize - difference; tableWindow.Resize(newSize, true); return; // At next iteration this code should not be executed because sizes will be the same, unless the player resizes the window } // If we don't know where the player is seated, we don't need to process any further if (table.CurrentHeroSeat == 0) { return; } /* Try to match player cards */ List <Bitmap> playerCardImages = new List <Bitmap>(); ArrayList playerCardsActions = colorMap.GetPlayerCardsActions(table.CurrentHeroSeat); foreach (String action in playerCardsActions) { Rectangle actionRect = recognitionMap.GetRectangleFor(action); if (!actionRect.Equals(Rectangle.Empty)) { playerCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect)); } else { Trace.WriteLine("Warning: could not find a rectangle for action " + action); } } CardList playerCards = matcher.MatchCards(playerCardImages, false); if (playerCards != null) { Trace.WriteLine("Matched player cards! " + playerCards.ToString()); handler.PlayerHandRecognized(playerCards); } // Dispose foreach (Bitmap image in playerCardImages) { if (image != null) { image.Dispose(); } } /* If community cards are supported, try to match them */ if (colorMap.SupportsCommunityCards) { List <Bitmap> communityCardImages = new List <Bitmap>(); ArrayList communityCardsActions = colorMap.GetCommunityCardsActions(); foreach (String action in communityCardsActions) { Rectangle actionRect = recognitionMap.GetRectangleFor(action); if (!actionRect.Equals(Rectangle.Empty)) { communityCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect)); } else { Trace.WriteLine("Warning: could not find a rectangle for action " + action); } } // We try to identify as many cards as possible CardList communityCards = matcher.MatchCards(communityCardImages, true); if (communityCards != null && communityCards.Count > 0) { Trace.WriteLine("Matched board cards! " + communityCards.ToString()); handler.BoardRecognized(communityCards); } // Dispose foreach (Bitmap image in communityCardImages) { if (image != null) { image.Dispose(); } } } // Dispose screenshot if (screenshot != null) { screenshot.Dispose(); } }