人物图像细化

发布于 2024-12-01 01:27:14 字数 271 浏览 2 评论 0原文

我正在做一个 ocr 应用程序。我很困惑如何倾斜这样的图像:

在此处输入图像描述

其次,我有一个带有多种字体的字符图像尺寸。问题是:如何将它们细化为相同大小

http://upload.wikimedia.org/wikipedia/commons/ 9/93/Skel.png

im doing an ocr application . im confusing that how to do skew an image like this :

enter image description here

Second ,i have a character image with many font size. the problem is : how to thin them to the same size like this

http://upload.wikimedia.org/wikipedia/commons/9/93/Skel.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路还长,别太狂 2024-12-08 01:27:14

对于第一点:找到文本旋转的角度,然后将图像旋转该角度。在您的示例中,您可以通过查找边缘上的大黑色斑块与白色区域之间的线条角度来完成此操作。查看边缘检测hough 变换 帮助您找到线条,然后帮助您找到它们的角度。 OpenCV 对这两种算法都有很好的实现。

对于第二点:这是形态学操作二元骨架的实际应用。

For your first point: find the angle by which the text is rotated, and rotate your image by that angle. In your sample you can do this by finding the angles of the lines between the large black patches on the edges and the white areas. Look into edge detection and hough transform to help you find the lines, and then help you find their angle. OpenCV has a good implementation of both algorithms.

For your second point: that is the morphological operation binary skeleton in action.

戏剧牡丹亭 2024-12-08 01:27:14

您可以使用以下代码来检测和纠正倾斜,但如果您获得任何细化算法,我需要您的帮助...假设输入图像位于图片框上...

        try
        {
            //Check if there exists an image on the picture box
            if (pictureBox1.Image == null)
            {
                MessageBox.Show("Please load an image first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                uploadImageToolStripMenuItem.PerformClick();
                return;
            }                
            Bitmap image = new Bitmap(pictureBox1.Image);
            BitmapData imageData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                    ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            //document image skew detection starts here
            DocumentSkewChecker skewChecker = new DocumentSkewChecker();
            // get documents skew angle
            double angle = skewChecker.GetSkewAngle(imageData);
            // create rotation filter and rotate image applying the filter
            RotateBilinear rotationFilter = new RotateBilinear(-angle);
            rotationFilter.FillColor = Color.White;
            image.UnlockBits(imageData);
            //if the angle is more 90 or 180, consider it as a normal image or if it is not, perform a skew correction
            if (-angle == 90 || -angle == 180)
            {
                pictureBox1.Image = image;
                pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                return;
            }

            //Bitmap rotatedImage = rotationFilter.Apply();
            //draw a bitmap based on the skew angle...
            Bitmap returnBitmap = new Bitmap(image.Width, image.Height);
            Graphics g = Graphics.FromImage(returnBitmap);
            g.TranslateTransform((float)image.Width / 2, (float)image.Height / 2);
            g.RotateTransform(((float)angle));
            g.TranslateTransform(-(float)image.Width / 2, -(float)image.Height / 2);
            g.DrawImage(image, new Point(0, 0));

            pictureBox1.Image = returnBitmap;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

        }

you can use the following code for detecting and correcting skew but i need your help if you get any thinning algorithms...asume the input image is on the picture box....

        try
        {
            //Check if there exists an image on the picture box
            if (pictureBox1.Image == null)
            {
                MessageBox.Show("Please load an image first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                uploadImageToolStripMenuItem.PerformClick();
                return;
            }                
            Bitmap image = new Bitmap(pictureBox1.Image);
            BitmapData imageData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                    ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            //document image skew detection starts here
            DocumentSkewChecker skewChecker = new DocumentSkewChecker();
            // get documents skew angle
            double angle = skewChecker.GetSkewAngle(imageData);
            // create rotation filter and rotate image applying the filter
            RotateBilinear rotationFilter = new RotateBilinear(-angle);
            rotationFilter.FillColor = Color.White;
            image.UnlockBits(imageData);
            //if the angle is more 90 or 180, consider it as a normal image or if it is not, perform a skew correction
            if (-angle == 90 || -angle == 180)
            {
                pictureBox1.Image = image;
                pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                return;
            }

            //Bitmap rotatedImage = rotationFilter.Apply();
            //draw a bitmap based on the skew angle...
            Bitmap returnBitmap = new Bitmap(image.Width, image.Height);
            Graphics g = Graphics.FromImage(returnBitmap);
            g.TranslateTransform((float)image.Width / 2, (float)image.Height / 2);
            g.RotateTransform(((float)angle));
            g.TranslateTransform(-(float)image.Width / 2, -(float)image.Height / 2);
            g.DrawImage(image, new Point(0, 0));

            pictureBox1.Image = returnBitmap;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文