private BitmapSource VisualizeResult(VideoFrame frame) { // Draw any results on top of the image. BitmapSource visImage = frame.Image.ToBitmapSource(); LiveCameraResult result = _latestResultsToDisplay; if (result != null) { // See if we have local face detections for this image. var clientFaces = (OpenCvSharp.Rect[])frame.UserData; if (clientFaces != null && result.Faces != null) { // If so, then the analysis results might be from an older frame. We need to match // the client-side face detections (computed on this frame) with the analysis // results (computed on the older frame) that we want to display. MatchAndReplaceFaceRectangles(result.Faces, clientFaces); } if (this.gameState == GameState.Explain) { this.Dispatcher.BeginInvoke((Action)(() => { RightImage.Source = ImageProvider.Instructions; //visImage = Visualization.DrawExplain(visImage); })); } else if (this.gameState == GameState.RoundBegin) { visImage = VisualizeStartRound(frame); } else if (this.gameState == GameState.RoundEnd) { visImage = VisualizeEndRound(frame); } else if (this.gameState == GameState.Game) { // Compute round score Dictionary <Guid, int> scores = round.ComputeFrameScorePerPlayer(result); scoringSystem.AddToCurrentRound(scores); visImage = Visualization.DrawFaces(visImage, round, result.Identities, scoringSystem, _mode); SavePlayerImages(frame.Image.ToBitmapSource(), result); } else if (this.gameState == GameState.Participants) { visImage = Visualization.DrawParticipants(visImage, result.Faces); } else if (this.gameState == GameState.GameEnd) { _grabber.StopProcessingAsync(); visImage = VisualizeEndGame(frame); } } return(visImage); }