Exemple #1
0
        private void buttonClassify_Click(object sender, EventArgs e)
        {
            //List<ClassifiedShape> records = new List<ClassifiedShape>();
            //foreach (DataGridViewRow i in dataGridViewClassifiedShape.Rows)
            //{
            //    records.Add(i.DataBoundItem as ClassifiedShape);
            //}
            //var groupedList = GroupHistory(records);
            //foreach(var i in groupedList)
            //{
            //    Debug.WriteLine(i.shapeClass + " " + i.PchPer + " " + i.AchAerAlt);
            //}
            ImageHandler         imageHandler = new ImageHandler(new Bitmap(pictureBox1.Image));
            List <List <Point> > edges        = imageHandler.GetEdges();
            Bitmap    tempDraw = new Bitmap(pictureBox1.Image);
            Graphics  graphics = Graphics.FromImage(tempDraw);
            Relations relation = new Relations();

            foreach (List <Point> edge in edges)
            {
                List <Point>     desu             = edge.OrderBy(x => Math.Atan2(x.X, x.Y)).ToList();
                ShapeRecognition recognizer       = new ShapeRecognition(new Polygon2D(desu));
                Polygon2D        convexHull       = recognizer.ConvexHull;
                List <Point>     convexHullPoints = convexHull.Points;
                for (int i = 1; i < convexHullPoints.Count(); i++)
                {
                    graphics.DrawLine(new Pen(Color.Red), convexHullPoints[i - 1], convexHullPoints[i]);
                }
                labelShapePointCountVal.Text = pointList.Count.ToString();
                labelConvHullPntCntVal.Text  = convexHullPoints.Count().ToString();
                graphics.DrawRectangle(new Pen(Color.Blue), recognizer.BoundingRectangle);
                DrawTriangle(graphics, recognizer.NestedTriangle);
                relation = recognizer.GetRelations();
            }
            pictureBox1.Image = tempDraw;

            ClassifiedShape   classifiedShape = new ClassifiedShape(relation, ShapeClass.Rectangle);
            ShapeClass        shapeClass      = Classifier.Classify(classifiedShape, features);
            string            messageBoxText  = "Class: " + shapeClass.ToString();
            string            caption         = "Class";
            MessageBoxButtons button          = MessageBoxButtons.OK;

            MessageBox.Show(messageBoxText, caption, button);
        }
Exemple #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            //switch (tabControl1.SelectedIndex)
            //{
            //    case 0:
            //        ClearCanvas();
            //        break;
            //    case 1:
            ImageHandler         imageHandler = new ImageHandler(new Bitmap(pictureBox1.Image));
            List <List <Point> > edges        = imageHandler.GetEdges();
            Bitmap   tempDraw = new Bitmap(pictureBox1.Image);
            Graphics graphics = Graphics.FromImage(tempDraw);

            foreach (List <Point> edge in edges)
            {
                List <Point>     desu             = edge.OrderBy(x => Math.Atan2(x.X, x.Y)).ToList();
                ShapeRecognition recognizer       = new ShapeRecognition(new Polygon2D(desu));
                Polygon2D        convexHull       = recognizer.ConvexHull;
                List <Point>     convexHullPoints = convexHull.Points;
                for (int i = 1; i < convexHullPoints.Count(); i++)
                {
                    graphics.DrawLine(new Pen(Color.Red), convexHullPoints[i - 1], convexHullPoints[i]);
                }
                labelShapePointCountVal.Text = pointList.Count.ToString();
                labelConvHullPntCntVal.Text  = convexHullPoints.Count().ToString();
                graphics.DrawRectangle(new Pen(Color.Blue), recognizer.BoundingRectangle);
                DrawTriangle(graphics, recognizer.NestedTriangle);
                currentRelation = recognizer.GetRelations();
            }
            pictureBox1.Image = tempDraw;
            //        break;
            //}
            ShapeClass      selectedClassItem = (ShapeClass)comboBoxShapeClass.SelectedItem;
            ClassifiedShape classifiedShape   = new ClassifiedShape(currentRelation, selectedClassItem);

            //ShapeClass shapeClass = Classifier.Classify(classifiedShape, features);

            //string messageBoxText = "Class: " + shapeClass.ToString();
            //string caption = "Class";
            //MessageBoxButtons button = MessageBoxButtons.OK;
            //MessageBox.Show(messageBoxText, caption, button);
            classifiedShapeBindingSource.Add(classifiedShape);
        }
Exemple #3
0
        public static ShapeClass Classify(ClassifiedShape shape, List <ClassifiedShape> features)
        {
            Debug.WriteLine(shape.ToString());
            ShapeClass      result        = ShapeClass.Cirle;
            ClassifiedShape circleFeature = features.Find(item => item.shapeClass == ShapeClass.Cirle);

            if (shape.Pch2Ach <= circleFeature.Pch2Ach)
            {
                result = ShapeClass.Cirle;
            }
            else
            {
                ClassifiedShape triangleFeature = features.Find(item => item.shapeClass == ShapeClass.Triangle);
                if (shape.AltAch >= triangleFeature.AltAch)
                {
                    result = ShapeClass.Triangle;
                }
                else
                {
                    ClassifiedShape rectangleFeature = features.Find(item => item.shapeClass == ShapeClass.Rectangle);
                    if (shape.PchPer >= rectangleFeature.PchPer)
                    {
                        result = ShapeClass.Rectangle;
                    }
                    else
                    {
                        ClassifiedShape ellipseFeature = features.Find(item => item.shapeClass == ShapeClass.Ellipse);
                        if (ellipseFeature.AchAerAlt <= ellipseFeature.AchAerAlt)
                        {
                            result = ShapeClass.Ellipse;
                        }
                    }
                }
            }
            return(result);
        }