/// <summary>
        /// Draw cross on the screen.
        /// </summary>
        /// <param name="Image"></param>
        /// <param name="Center"></param>
        public static void DrawCross(ref Image <Bgr, Byte> Image, Point Center)
        {
            int thikness = 2;
            int size     = 10;

            Bgr crossColor = new Bgr(Color.BurlyWood);

            LineSegment2D[] myCross = SupportMethods.GetCross(Center, size, true);
            Image.Draw(myCross[0], crossColor, thikness);
            Image.Draw(myCross[1], crossColor, thikness);
        }
Beispiel #2
0
        /// <summary>
        /// Find the chessboard corners
        /// </summary>
        /// <param name="InputImage">Input image commpping from video camera.</param>
        /// <param name="OutputImage">Output image comming from image processor.</param>
        public static BoardConfiguration FindBoard(Bitmap InputImage, out Bitmap OutputImage)
        {
            #region Local variables

            // Figure Center
            Point figureCenter;
            // Figure BGR color
            Bgr bgrInFigureColor;
            // Vector image of figure
            CircleF circleFigure;
            //
            Color colorTransformedColor;
            //
            double hueChanel;
            double saturationChanel;
            double valueChanel;
            //
            Color circleColor;

            // Board configuration
            BoardConfiguration currentConfiguration = new BoardConfiguration();

            #endregion

            #region Equalize the image

            // Convert a BGR image to HLS range
            Emgu.CV.Image <Hls, Byte> imageHsi = new Image <Hls, Byte>(InputImage);

            // Equalize the Intensity Channel
            imageHsi[1]._EqualizeHist();
            imageHsi[2]._EqualizeHist();

            // Convert the image back to BGR range
            Emgu.CV.Image <Bgr, Byte> DrawingImage = imageHsi.Convert <Bgr, Byte>();

            // Geometric orientation image
            Emgu.CV.Image <Gray, Byte> BlobImage = imageHsi[1].Convert <Gray, Byte>();

            // Create the font.
            MCvFont TextFont = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.5, 1.5);

            #endregion

            try
            {
                // Get bord marker points,
                MarkersList = Board.GetBoardMarkers(BlobImage.ToBitmap());

                // If repers are 4 the proseed to describe the board.
                if (MarkersList.Length == MarkersCount)
                {
                    // Set playboard size.
                    Board.SetSize(BoardSize);

                    #region Get perspective flat image.

                    // Get perspective flat image.
                    Image <Bgr, byte> newImage = SupportMethods.GetPerspectiveFlatImage(DrawingImage, BoardSize, MarkersList);

                    #endregion

                    for (int indexFigure = 0; indexFigure < 24; indexFigure++)
                    {
                        // Set the figure center
                        figureCenter = Board.FigurePosition(indexFigure);
                        //
                        bgrInFigureColor = Board.GetFigureColor(newImage, Board.GetBoundingBox(figureCenter));
                        //
                        colorTransformedColor = Color.FromArgb(255, (byte)bgrInFigureColor.Red, (byte)bgrInFigureColor.Green, (byte)bgrInFigureColor.Blue);
                        //
                        SupportMethods.ColorToHSV(colorTransformedColor, out hueChanel, out saturationChanel, out valueChanel);
                        // Preset the color configuration
                        valueChanel      = 1.0;
                        saturationChanel = 1.0;
                        // Find the playr
                        int figure = FigureColorDefinitions.WhoIsThePlayer((int)hueChanel);
                        // Fill the board configuration
                        currentConfiguration.Figure[indexFigure] = figure;

                        #region Draw

                        if (!((hueChanel > HueChanelMin) && (hueChanel < HueChanelMax)) && (figure != -1))
                        {
                            circleColor = SupportMethods.ColorFromHSV(hueChanel, saturationChanel, valueChanel);
                            // Create figure to draw.
                            circleFigure = new CircleF(figureCenter, 10.0f);
                            // Draw circle
                            newImage.Draw(circleFigure, new Bgr(circleColor), 5);
                            // Write text
                            //
                            #region Draw label to the processed image.

                            newImage.Draw(String.Format("{0}", FigureColorDefinitions.WhoIsThePlayer((int)hueChanel)), ref TextFont, figureCenter, new Bgr(0, 0, 0));
                            //drawingImage.Draw(vectorWithSmallestY, RedColor, 2);
                            #endregion
                        }

                        #endregion
                    }

                    // Show unperspective image
                    //CvInvoke.cvShowImage("Perspective", newImage);
                    DrawingImage = newImage;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception: {0}", exception.Message);
            }

            // Apply the output image.
            OutputImage = new Bitmap(DrawingImage.Resize(OutputImageWidth, OutputImageHeight, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR).ToBitmap());

            return(currentConfiguration);
        }