【发布时间】:2011-08-23 03:04:26
【问题描述】:
我正在做一个 ocr 应用程序。我很困惑如何像这样倾斜图像:
第二,我有一个字体大小很多的字符图像。问题是:如何将它们变薄到像这样的相同尺寸
【问题讨论】:
标签: image-processing computer-vision ocr
我正在做一个 ocr 应用程序。我很困惑如何像这样倾斜图像:
第二,我有一个字体大小很多的字符图像。问题是:如何将它们变薄到像这样的相同尺寸
【问题讨论】:
标签: image-processing computer-vision ocr
对于您的第一点:找到文本旋转的角度,然后将图像旋转该角度。在您的示例中,您可以通过查找边缘上的大黑色斑块和白色区域之间的线条角度来做到这一点。查看edge detection 和hough transform 以帮助您找到线条,然后帮助您找到它们的角度。 OpenCV 对这两种算法都有很好的实现。
第二点:这是形态学运算binary skeleton 的作用。
【讨论】:
您可以使用以下代码来检测和纠正偏斜,但如果您有任何细化算法,我需要您的帮助...假设输入图像在图片框上......
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);
}
【讨论】: