public TimedScreenshotTaker(int msInterval, Window window) { this.scrTaker = new ScreenshotTaker(); this.msInterval = msInterval; this.window = window; this.running = false; }
private void ProcessPlayerCardActions(Bitmap screenshot, int seat, bool isHero) { /* Try to match player cards */ List <Bitmap> playerCardImages = new List <Bitmap>(); ArrayList playerCardsActions = colorMap.GetPlayerCardsActions(seat); foreach (String action in playerCardsActions) { Globals.Director.WriteDebug(" --- PlayerCardsActions: " + action); Rectangle actionRect = recognitionMap.GetRectangleFor(action); if (!actionRect.Equals(Rectangle.Empty)) { //Globals.Director.WriteDebug(" --- Found Rectangle for:: " + action); playerCardImages.Add(ScreenshotTaker.Slice(screenshot, actionRect)); } else { Globals.Director.WriteDebug("Warning: could not find a rectangle for action " + action); } } //Globals.Director.WriteDebug("Matching player cards! "); //playerCardsActions CardList playerCards = matcher.MatchCards(playerCardImages, false, playerCardsActions, table.MatchHistogramThreshold(), table.MatchTemplateThreshold(), table.AllowableMatchTemplateThreshold()); if (playerCards != null && isHero) { Globals.Director.WriteDebug("Matched player cards! " + playerCards.ToString()); handler.PlayerHandRecognized(playerCards); } else if (playerCards != null && !isHero) { Globals.Director.WriteDebug(" -- NOT hero cards. Seat " + seat + " Cards: " + playerCards.ToString()); handler.VillainHandRecognized(playerCards, seat); } else { Globals.Director.WriteDebug(" --- SEAT: " + seat + " Did not find any matching player cards "); } // Dispose foreach (Bitmap image in playerCardImages) { if (image != null) { image.Dispose(); } } }
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(); } } } }
/* Tools stuff */ public bool TakeActiveWindowScreenshot(bool clientOnly) { if (windowsListener != null) { Window w = new Window(windowsListener.CurrentForegroundWindowTitle); ScreenshotTaker st = new ScreenshotTaker(); Bitmap screenshot = st.Take(w, clientOnly, ScreenshotTaker.Mode.PrintScreen); try { screenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\screenshot.png"); } catch (Exception) { return(false); } return(true); } return(false); }
/* Tools stuff */ public bool TakeActiveWindowScreenshot(bool clientOnly) { if (windowsListener != null) { Window w = new Window(windowsListener.CurrentForegroundWindowHandle); ScreenshotTaker st = new ScreenshotTaker(); Bitmap screenshot = st.Take(w, clientOnly, ScreenshotTaker.Mode.PrintScreen); try { screenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\screenshot.png"); } catch (Exception) { return(false); } WriteDebug("--- Try to analize the screen shoot"); // Table foundWindow = FindTableByWindowTitle(w.Title); Table foundWindow = FindTableByWindowHandle(w.handle); if (null != foundWindow && foundWindow.IsVisualRecognitionPossible()) { foundWindow.VisuallyProcessImage(screenshot); } else { Globals.Director.WriteDebug(" ERROR: could not find table for window: " + w.Title); } return(true); } return(false); }
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(); } }