예제 #1
0
 public Form1()
 {
     InitializeComponent();
     process = new CSVProcess();
     imgproc = new ImageProcessing();
     texture = new TextureRes();
 }
예제 #2
0
        public int[,] GetCountorPoints(Bitmap img)
        {
            int          colorBackr = img.GetPixel(0, 0).R;
            Bitmap       tecImg = new Bitmap(img);
            List <Point> objectsPoints = new List <Point>();
            TextureRes   texture = new TextureRes();
            int          i = 0, j = 0;

            while (i < img.Width - 1)
            {
                if (img.GetPixel(i, j).R != colorBackr)
                {
                    objectsPoints.Add(new Point(i, j));
                }
                if (j == img.Height - 1)
                {
                    j = 0;
                    i++;
                }
                else
                {
                    j++;
                }
            }
            int xmin = int.MaxValue, ymin = int.MaxValue, ymax = int.MinValue, xmax = int.MinValue;

            foreach (Point pt in objectsPoints)
            {
                if (pt.X > xmax)
                {
                    xmax = pt.X;
                }
                if (pt.X < xmin)
                {
                    xmin = pt.X;
                }
                if (pt.Y > ymax)
                {
                    ymax = pt.Y;
                }
                if (pt.Y < ymin)
                {
                    ymin = pt.Y;
                }
            }

            int[,] resmat = new int[xmax - xmin + 1, ymax - ymin + 1];
            for (int k = 0; k < xmax - xmin + 1; k++)
            {
                for (int l = 0; l < ymax - ymin + 1; l++)
                {
                    resmat[k, l] = -1;
                }
            }
            int y1 = 0, x1 = 0;

            for (int y = ymin; y <= ymax; y++)
            {
                for (int x = xmin; x <= xmax; x++)
                {
                    if (tecImg.GetPixel(x, y).R != 0)
                    {
                        resmat[x1, y1] = tecImg.GetPixel(x, y).R;
                    }
                    x1++;
                }
                x1 = 0;
                y1++;
            }
            return(resmat);
        }