Пример #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);
        }
Пример #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);
        }
Пример #3
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();
        }