public static Classes.Element calcAtributesOfElement(Skeleton sk, int cell_index)
        {
            Bitmap bm         = new Bitmap(sk.Size.X, sk.Size.Y);
            int    all_length = 0;

            foreach (Skeleton.cell sc in sk.list_of_cell)
            {
                all_length += sc.list_of_node.Count;
            }
            Skeleton.cell selected_cell = null;
            try
            {
                selected_cell = sk.list_of_cell[cell_index];
            }
            catch (Exception e) { }
            int    e_type = 0;
            Point  Pb, Pe;
            double length        = 0;
            int    curvature     = 0;
            double max_curvature = 0;

            // конечная и начальная точки элемента
            Pb = new Point(selected_cell.list_of_node[0].x, selected_cell.list_of_node[0].y);
            Pe = new Point(selected_cell.list_of_node[selected_cell.list_of_node.Count - 1].x,
                           selected_cell.list_of_node[selected_cell.list_of_node.Count - 1].y);
            double current_curvature = 0;

            foreach (Skeleton.node sn in selected_cell.list_of_node)
            {
                bm.SetPixel(sn.x, sn.y, Color.White);
                length           += 1;
                current_curvature = Classes.OCR_System.calcCurvature(Pe.Y - Pb.Y, -(Pe.X - Pb.X),
                                                                     (Pe.X - Pb.X) * Pb.Y + (Pe.Y - Pb.Y) * Pb.X,
                                                                     sn.x, sn.y
                                                                     );
                if (max_curvature < current_curvature)
                {
                    max_curvature = current_curvature;
                }
            }
            // e_type = выход 1 слоя при входном изображении bm
            int[] fl_out = Classes.OCR_System.FirstLayer.Raspozn(Classes.OCR_System.convertToTXT(
                                                                     Vectorizer_Form.CopyBitmap(bm, new Rectangle(0, 0, bm.Width, bm.Height), 64)
                                                                     ));
            for (int k = 0; k < fl_out.Length; k++)
            {
                if (fl_out[k] == 1)
                {
                    e_type = k;
                    break;
                }
            }
            // длина элемента относительно общей длины скелета
            length /= all_length;
            // кривизна элемента
            curvature = (int)max_curvature;

            return(new Classes.Element(e_type, Pb, Pe, length, curvature));
        }
Esempio n. 2
0
        private void Paint_element(Skeleton.cell sc, int width, int height)
        {
            Bitmap bm = new Bitmap(width, height);

            foreach (Skeleton.node sn in sc.list_of_node)
            {
                bm.SetPixel(sn.x, sn.y, Color.White);
            }
            ibReader.Image = new Image <Gray, byte>(bm);
        }