private void DetectBoardRectangles() { ImageProcessor imageProcessor = m_MainModel.ImageProcessor; Image <Gray, Byte> erodedGrayImage = imageProcessor.GrayImage.Erode(1); Image <Gray, Byte> erodedBlackAndWhite = erodedGrayImage.ThresholdBinaryInv(new Gray(imageProcessor.Threshold), new Gray(255)); m_MainModel.ImageProcessor.BlackAndWhiteImage.Erode(1); List <MCvBox2D> foundRectangles = BoardImageModel.CollectRectangles(erodedBlackAndWhite); m_MainModel.ImageProcessor.UpdateRectanglesImage(foundRectangles); if (foundRectangles.Count == m_MainModel.BoardImageModel.ExpectedRectangleCount) { m_MainModel.BoardImageModel.InitializeRectangles(foundRectangles); if (m_MainModel.BoardImageModel.IsEmpty(m_MainModel.ImageProcessor.BlackAndWhiteImage)) { this.Dispatch(new ControllerEvent(ControllerSignal.BoardInitialized)); } } }
private void DetectHumanMove() { BoardImageModel boardImageModel = m_MainModel.BoardImageModel; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { if (m_MainModel.BoardManager.Board[x, y] == CellState.Empty) { if (boardImageModel.IsFilled(x, y, m_MainModel.ImageProcessor.BlackAndWhiteImage)) { // We found the new piece m_MainModel.BoardManager.MakeMove(x, y); this.Dispatch(new ControllerEvent(ControllerSignal.HumanMoved)); } } } } }