コード例 #1
0
ファイル: Form1.cs プロジェクト: kevin840307/ImageProcess
        private void pic_grid_Paint(object sender, PaintEventArgs e)
        {
            if (!_gridInit)
            {
                LinkPoint();
                return;
            }

            DrawF draw = new DrawF(79.0f, 5.0f, 5.0f);

            for (int col = 0; col < 5; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    PointF2D point = _points[col, row];
                    if (row < 4)
                    {
                        PointF2D rightPoint = _points[col, row + 1];
                        draw.drawLine(e.Graphics, point.X, point.Y, rightPoint.X, rightPoint.Y);
                    }

                    if (col < 4)
                    {
                        PointF2D bottomPoint = _points[col + 1, row];
                        draw.drawLine(e.Graphics, point.X, point.Y, bottomPoint.X, bottomPoint.Y);
                    }
                }
            }
            _gridInit = false;
        }
コード例 #2
0
ファイル: DrawF.cs プロジェクト: kevin840307/ImageProcess
        public PointF2D getBlockPoint(float x, float y)
        {
            PointF2D point = new PointF2D();

            point.X = (_center.X / _offset + x) * _offset;
            point.Y = (_center.Y / _offset - y) * _offset;
            return(point);
        }
コード例 #3
0
ファイル: DrawF.cs プロジェクト: kevin840307/ImageProcess
        // drawGradient畫一個梯度
        // point: 座標
        // U: x向量
        // V: y向量
        // maxSum: 最大向量和
        public void drawGradient(Graphics graphics
                                 , PointF2D point
                                 , float U, float V, float maxSum)
        {
            // 鄰邊 = U = x
            // 對邊 = V = y
            float absU = Math.Abs(U);
            float absV = Math.Abs(V);

            // atan取弧度(tan = 對邊 / 鄰邊
            float radian = absU != 0 ? (float)Math.Atan(absV / absU) : (float)(Math.PI * 0.5);

            Console.WriteLine(radian / Math.PI * 180);

            // cos = 鄰邊 / 斜邊, sin = 對邊 / 斜邊
            float xCos = U != 0.0f ? (float)Math.Cos(radian) : 1.0f;
            float ySin = V != 0.0f ? (float)Math.Sin(radian) : 0.0f;

            float xDirection = U < 0.0f ? -1.0f : U > 0 ? 1.0f : 0.0f;
            float yDirection = V < 0.0f ? 1.0f : V > 0 ? -1.0f : 0.0f;


            // 計算顯示長度比例
            float max    = absU > absV ? absU : absV;
            float maxLen = (max / maxSum * _offset);

            for (float index = 0; index < maxLen; index += 0.01f)
            {
                // 取得斜邊
                // 取得x + 方向和y + 方向(對邊)
                float bevel = index / xCos;
                float x     = index * xDirection;
                float y     = ySin * bevel * yDirection;

                if (Math.Abs(y) > maxLen)
                {
                    return;
                }

                drawPointLine(graphics, Brushes.Black, point.X + x, point.Y + y);
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: kevin840307/ImageProcess
        private PointF2D[,] GetInitPoints()
        {
            PointF2D[,] points = new PointF2D[5, 5];
            int fixWidth  = _fileImage.Width >> 2;
            int fixHeight = _fileImage.Height >> 2;

            //DrawF draw = new DrawF(79.0f, 5.0f, 5.0f);
            //draw.drawBlock(e.Graphics, 4.0f, 4.0f);
            pic_grid.Controls.Clear();
            for (int col = 0; col < 5; col++)
            {
                float fixCol = fixHeight * col + 10.0f;
                for (int row = 0; row < 5; row++)
                {
                    float fixRow = fixWidth * row + 10.0f;
                    points[col, row] = new PointF2D(fixRow, fixCol);

                    PictureBox pointPic = new PictureBox();
                    pointPic.Location = new Point((int)fixRow - 5, (int)fixCol - 5);
                    pointPic.Size     = new Size(13, 13);
                    pointPic.Image    = new Bitmap(Environment.CurrentDirectory + @"\red.png");
                    //pointPic.Image = new Bitmap( @"D:\VisualStudio\VisualStudioProject\IVCLibrary\x64\Debug\red.png");
                    pointPic.Name     = row + "," + col;
                    pointPic.SizeMode = PictureBoxSizeMode.Zoom;
                    pointPic.Parent   = pic_grid;
                    pic_grid.Controls.Add(pointPic);

                    pointPic.MouseMove += new MouseEventHandler(point_pic_MouseMove);
                    pointPic.MouseDown += new MouseEventHandler(point_pic_MouseDown);
                    pointPic.MouseUp   += new MouseEventHandler(point_pic_MouseUp);
                    //draw.drawPoint(e.Graphics, Brushes.Red, fixRow, fixCol);
                    //draw.drawImage(e.Graphics, image, fixRow, fixCol);
                }
            }
            return(points);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: kevin840307/ImageProcess
        private void LinkPoint()
        {
            DrawF draw = new DrawF(79.0f, 5.0f, 5.0f);
            BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            BufferedGraphics        bufferGraphics = currentContext.Allocate(pic_grid.CreateGraphics(), pic_grid.DisplayRectangle);

            _gridImage = new Bitmap(_fileImage.Width, _fileImage.Height);
            Graphics graphics    = bufferGraphics.Graphics;
            Graphics graphicsBMP = Graphics.FromImage(_gridImage);

            graphics.Clear(pic_grid.BackColor);
            graphicsBMP.FillRectangle(Brushes.White, 0, 0, _fileImage.Width, _fileImage.Height);
            for (int col = 0; col < 5; col++)
            {
                for (int row = 0; row < 5; row++)
                {
                    PointF2D point = _points[col, row];
                    float    x1    = point.X - 10 == _fileImage.Width ? point.X - 11 : point.X - 10;
                    float    y1    = point.Y - 10 == _fileImage.Height ? point.Y - 11 : point.Y - 10;
                    if (row < 4)
                    {
                        PointF2D rightPoint = _points[col, row + 1];
                        float    x2         = rightPoint.X - 10 == _fileImage.Width ? rightPoint.X - 11 : rightPoint.X - 10;
                        float    y2         = rightPoint.Y - 10 == _fileImage.Height ? rightPoint.Y - 11 : rightPoint.Y - 10;
                        draw.drawLine(graphics, point.X, point.Y, rightPoint.X, rightPoint.Y);
                        draw.drawLine(graphicsBMP, x1, y1, x2, y2, 3);
                    }

                    if (col < 4)
                    {
                        PointF2D bottomPoint = _points[col + 1, row];
                        float    x2          = bottomPoint.X - 10 == _fileImage.Width ? bottomPoint.X - 11 : bottomPoint.X - 10;
                        float    y2          = bottomPoint.Y - 10 == _fileImage.Height ? bottomPoint.Y - 11 : bottomPoint.Y - 10;
                        draw.drawLine(graphics, point.X, point.Y, bottomPoint.X, bottomPoint.Y);
                        draw.drawLine(graphicsBMP, x1, y1, x2, y2, 3);
                    }
                }
            }
            if (ch_timely.Checked)
            {
                pic_result.Image = _lib.PerspectiveTransform8bit(_grayImage, _points, _transType);
            }
            //int[,] graph = new int[pic_grid.Height, pic_grid.Width];
            //int mark = 1;
            //List<int> links = new List<int>();
            //links.Add(0);
            //for (int row = 1; row < bmpPic.Height - 1; row++)
            //{
            //    for (int col = 1; col < bmpPic.Width - 1; col++)
            //    {
            //        List<int> link = new List<int>();

            //        if (bmpPic.GetPixel(col, row).R != 255)
            //        {
            //            continue;
            //        }

            //        if (graph[row - 1, col - 1] != 0)
            //        {
            //            link.Add(graph[row - 1, col - 1]);
            //        }

            //        if (graph[row - 1, col] != 0)
            //        {
            //            link.Add(graph[row - 1, col]);
            //        }

            //        if (graph[row - 1, col + 1] != 0)
            //        {
            //            link.Add(graph[row - 1, col + 1]);
            //        }

            //        if (graph[row, col - 1] != 0)
            //        {
            //            link.Add(graph[row, col - 1]);
            //        }

            //        if (link.Count == 0)
            //        {
            //            links.Add(mark);
            //            graph[row, col] = mark++;
            //        }
            //        else
            //        {
            //            link.Sort();
            //            int minLink = links[link[0]];
            //            for (int index = 0; index < link.Count; index++)
            //            {
            //                if (minLink < links[link[index]])
            //                {
            //                    links[link[index]] = minLink;
            //                }
            //                else if (minLink > links[link[index]])
            //                {
            //                    links[link[0]] = links[link[index]];
            //                }
            //            }
            //            graph[row, col] = minLink;
            //        }
            //    }
            //}

            //for (int index = 1; index < links.Count(); index++)
            //{
            //    int saveValue = links[index];
            //    int saveValueIndex = index;
            //    while (saveValue != saveValueIndex)
            //    {
            //        saveValue = links[links[saveValueIndex]];
            //        saveValueIndex = links[saveValueIndex];
            //    }
            //    links[index] = saveValue;
            //}
            //HashSet<int> companyTeams = new HashSet<int>();
            //for (int row = 1; row < bmpPic.Height - 1; row++)
            //{
            //    for (int col = 1; col < bmpPic.Width - 1; col++)
            //    {

            //        if (bmpPic.GetPixel(col, row).R != 255)
            //        {
            //            continue;
            //        }
            //        graph[row, col] = links[graph[row, col]];
            //        companyTeams.Add(graph[row, col]);
            //    }
            //}

            //Color[] colors = new Color[companyTeams.Count + 1];
            //Dictionary<int, int> norml = new Dictionary<int, int>();
            //for (int index = 0; index < companyTeams.Count + 1; index++)
            //{
            //    colors[index] = GetColor(index);
            //}
            //norml[0] = 0;
            //int offset = 1;
            //foreach (int data in companyTeams)
            //{
            //    norml[data] = offset;
            //    offset++;
            //}

            //for (int row = 0; row < pic_grid.Height; row++)
            //{
            //    for (int col = 0; col < pic_grid.Width; col++)
            //    {
            //        //bmpPic.SetPixel(col, row, colors[norml[graph[row, col]]]);
            //        if (bmpPic.GetPixel(col, row).R != 0)
            //        {
            //            continue;
            //        }
            //    }
            //}
            //_gridImage.Save(@"D:/test.bmp");
            bufferGraphics.Render(pic_grid.CreateGraphics());
            bufferGraphics.Dispose();
        }
コード例 #6
0
ファイル: DrawF.cs プロジェクト: kevin840307/ImageProcess
 public DrawF(float offset, float x, float y)
 {
     _center = new PointF2D(x * offset, y * offset);
     _offset = offset;
 }
コード例 #7
0
ファイル: DrawF.cs プロジェクト: kevin840307/ImageProcess
 public DrawF(float offset)
 {
     _center = new PointF2D(5.0f * offset, 5.0f * offset);
     _offset = offset;
 }