Example #1
0
 public ClassifiedShape(Relations relations, ShapeClass shapeClass)
 {
     // this.relations = relations;
     LenPch          = Math.Round(relations.LenPch, 5);
     Pch2Ach         = Math.Round(relations.Pch2Ach, 5);
     AltAch          = Math.Round(relations.AltAch, 5);
     PchPer          = Math.Round(relations.PchPer, 5);
     AchAerAlt       = Math.Round(relations.AchAerAlt, 5);
     AltAer          = Math.Round(relations.AltAer, 5);
     this.shapeClass = shapeClass;
 }
Example #2
0
        public Relations GetRelations()
        {
            Relations relations     = new Relations();
            double    areaCH        = PolygonArea(ConvexHull);
            double    perimeterCH   = PerimeterOfPolygon(ConvexHull);
            double    areaRectangle = BoundingRectangle.Width * BoundingRectangle.Height;
            double    areaTriangle  = AreaTriangle(NestedTriangle);

            relations.AltAch    = areaTriangle / areaCH;
            relations.LenPch    = PerimeterOfPolygon(OriginalPolygon) / perimeterCH;
            relations.Pch2Ach   = perimeterCH / areaCH;
            relations.PchPer    = perimeterCH / (2 * (BoundingRectangle.Width + BoundingRectangle.Height));
            relations.AchAerAlt = Math.Pow(areaCH, 2) / (areaRectangle * areaTriangle);
            relations.AltAer    = areaTriangle / areaRectangle;
            return(relations);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        private void RecordShape()
        {
            mouseIsDown = false;
            ShapeRecognition recognizer       = new ShapeRecognition(new Polygon2D(pointList));
            Polygon2D        convexHull       = recognizer.ConvexHull;
            List <Point>     convexHullPoints = convexHull.Points;

            for (int i = 1; i < convexHullPoints.Count(); i++)
            {
                graphObj.DrawLine(new Pen(Color.Red), convexHullPoints[i - 1], convexHullPoints[i]);
            }
            labelShapePointCountVal.Text = pointList.Count.ToString();
            labelConvHullPntCntVal.Text  = convexHullPoints.Count().ToString();
            graphObj.DrawRectangle(new Pen(Color.Black), recognizer.BoundingRectangle);
            DrawTriangle(recognizer.NestedTriangle);
            currentRelation = recognizer.GetRelations();
            //Clean some shits
            previousPointList = pointList.ToList();
            pointList.Clear();
        }