コード例 #1
0
        public static Image <Bgr, byte> DetectCups(Mat input_image)
        {
            Size size = new Size(700, 700);

            Image <Gray, byte> filtered_image = new Image <Gray, byte>(size);

            Image <Hsv, byte> preprocessed_image = PreProcessing.Preprocess(input_image, size, ShowHSV);

            //denoise, smoothe and threshold
            filtered_image = PreProcessing.FilterCups(preprocessed_image, ShowFiltered);

            //PreProcessing.FilterGlare( preprocessed_image, ShowFiltered );

            Image <Bgr, byte> output_image = new Image <Bgr, byte>(input_image.Size);

            output_image = input_image.ToImage <Bgr, byte>();
            CvInvoke.Resize(output_image, output_image, size);

            PreProcessing.DrawContours(output_image, PreProcessing.GetContours(filtered_image), filtered_image);

            return(output_image);
        }
コード例 #2
0
        public static void InitCupTracking(Mat input_image)
        {
            if (!TrackCups)
            {
                Cups = new CV_Cup[3];

                for (int i = 0; i < 3; i++)
                {
                    Cups[i] = new CV_Cup();
                }

                Size size = new Size(700, 700);

                //Load image
                Image <Gray, byte> filtered_image = new Image <Gray, byte>(size);

                //denoise, smoothe and threshold
                filtered_image = PreProcessing.FilterCups(PreProcessing.Preprocess(input_image, size, false), false);

                VectorOfVectorOfPoint contours = PreProcessing.GetContours(filtered_image);

                for (int i = 0; i < contours.Size; i++)
                {
                    if (i < 3)
                    {
                        Cups[i].Init(i, CvInvoke.BoundingRectangle(contours[i]));
                    }
                    else
                    {
                        Console.WriteLine("CV_Program: Too many contours during InitCupTracking()");
                    }
                }

                Console.WriteLine("CV_Program: InitCupTracking(): Found These Cups:");
                Console.WriteLine("CV_Program: InitCupTracking(): [" + Cups[0].CupID + "] " + Cups[0].BoundingBox);
                Console.WriteLine("CV_Program: InitCupTracking(): [" + Cups[1].CupID + "] " + Cups[1].BoundingBox);
                Console.WriteLine("CV_Program: InitCupTracking(): [" + Cups[2].CupID + "] " + Cups[2].BoundingBox);

                MinY = ((Cups[0].BoundingBox.Location.Y + Cups[1].BoundingBox.Location.Y + Cups[2].BoundingBox.Location.Y) / 3) - 80;

                float[] widths = new float[3];
                widths[0] = (float)Cups[0].BoundingBox.Width;
                widths[1] = (float)Cups[1].BoundingBox.Width;
                widths[2] = (float)Cups[2].BoundingBox.Width;

                float[] heights = new float[3];
                heights[0] = (float)Cups[0].BoundingBox.Height;
                heights[1] = (float)Cups[1].BoundingBox.Height;
                heights[2] = (float)Cups[2].BoundingBox.Height;

                MinWidth  = getMaxWidthOrHeight(widths);
                MinWidth *= 1.3f;

                MinHeight  = getMaxWidthOrHeight(heights);
                MinHeight *= 1.15f;

                AvgHeight = (Cups[0].BoundingBox.Height + Cups[1].BoundingBox.Height + Cups[2].BoundingBox.Height) / 3.0f;
                AvgWidth  = (Cups[0].BoundingBox.Width + Cups[1].BoundingBox.Width + Cups[2].BoundingBox.Width) / 3.0f;

                TrackCups = true;
            }
        }