Exemplo n.º 1
0
        /// <summary>
        /// Draws tracked data on a Uint16 infraredImage
        /// </summary>
        /// <param name="infraredImage"></param>
        private Mat DrawTrackedData(Mat infraredImage)
        {
            int thickness = Properties.UserSettings.Default.DataIndicatorThickness;
            int colorcode = Properties.Settings.Default.DataIndicatorColor;
            int padding   = Properties.Settings.Default.DataIndicatorPadding;


            CvInvoke.Normalize(infraredImage, infraredImage, 0, 255, NormType.MinMax, DepthType.Cv8U);



            Mat colImg = new Mat(infraredImage.Width, infraredImage.Height, DepthType.Cv8U, 3);



            CvInvoke.CvtColor(infraredImage, colImg, ColorConversion.Gray2Bgr, 3);

            if (screen.PrevPoints != null)
            {
                double[][] cameraSpaceCoordinates = cameraData.CameraToIR(screen.PrevPoints);
                ////double[][] cameraSpaceCoordinates = screen.PrevPoints;



                if (cameraSpaceCoordinates != null)
                {
                    int      width, height;
                    int      x, y;
                    double[] point;

                    for (int i = 0; i < cameraSpaceCoordinates.Length; i++)
                    {
                        point  = cameraSpaceCoordinates[i];
                        width  = 5;
                        height = 5;
                        x      = (int)point[0];
                        y      = (int)point[1];

                        Rectangle rect = new Rectangle(x - (width / 2) - padding, y - (height / 2) - padding, width + padding * 2, height + padding * 2);

                        /*
                         * CvInvoke.Rectangle(infraredImage, rect, new Gray(colorcode).MCvScalar, thickness); // 2 pixel box thick
                         *
                         * CvInvoke.PutText(infraredImage,
                         *              i.ToString(),
                         *              new System.Drawing.Point((int)prevPoints[i][0], (int)prevPoints[i][1]),
                         *              FontFace.HersheyComplex,
                         *              1.0,
                         *              new Gray(colorcode).MCvScalar);
                         */
                        if (screen.PointInfo[i].Visible)
                        {
                            CvInvoke.Rectangle(colImg, rect, new Bgr(100, 100, 0).MCvScalar, -1); // 2 pixel box thick
                        }
                        else
                        {
                            CvInvoke.Rectangle(colImg, rect, new Bgr(0, 0, 255).MCvScalar, thickness); // 2 pixel box thick
                        }



                        CvInvoke.PutText(colImg,
                                         i.ToString(),
                                         new System.Drawing.Point((int)point[0] - (width) + 2, (int)point[1] + (height / 2)),
                                         FontFace.HersheyPlain,
                                         .4,
                                         new Bgr(200, 200, 255).MCvScalar);
                    }
                }

                /*
                 * int height1 = 10;
                 * int width1 = 10;
                 * Rectangle rect1 = new Rectangle((int)missingx[0] - (width1 / 2) - padding, (int)missingx[1] - (height1 / 2) - padding, width1 + padding * 2, height1 + padding * 2);
                 * CvInvoke.Rectangle(colImg, rect1, new Bgr(255, 0, 255).MCvScalar, thickness); // 2 pixel box thick
                 */
            }
            return(colImg);
        }