2011-08-23 21 views
4

即時做一個ocr應用程序。 IM困惑是如何做到歪斜這樣一個形象:字符圖像變薄

enter image description here

其次,我有許多字體大小的文字圖像。問題是:如何瘦他們這樣

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

回答

3

相同尺寸的第一點:找到適合文本旋轉的角度,並通過角度旋轉圖像。在您的示例中,您可以通過查找邊緣上的大黑色補丁和白色區域之間的線條角度來做到這一點。看看edge detectionhough transform,以幫助您找到線條,然後幫助您找到他們的角度。 OpenCV對這兩種算法都有很好的實現。

對於你的第二點:這是形態操作binary skeleton在行動。

0

您可以使用下面的代碼來檢測和糾正歪斜,但我需要你的幫助,如果你得到任何細化算法... asume輸入圖像的圖片框....

 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); 

     }