Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1.   private void CannyEdgeDetection()
  2.         {
  3.             Image<Gray, Byte> grayImage = new Image<Gray, byte>(imageBox1.Image.Bitmap);
  4.             var blurredImage = grayImage.SmoothGaussian(5, 5, 0, 0);
  5.             var cannyImage = new UMat();
  6.             CvInvoke.Canny(blurredImage, cannyImage, 50, 150);
  7.  
  8.             Image<Gray, Byte> showCanny = new Image<Gray, byte>(cannyImage.Bitmap);
  9.             imageBox4.Image = showCanny;
  10.         }
  11.  
  12.         private void CannyOCR()
  13.         {
  14.             //sobel
  15.             Image<Bgr, Byte> img = new Image<Bgr, byte>(imageBox1.Image.Bitmap);
  16.             Image<Gray, byte> sobel = img.Convert<Gray, byte>().Sobel(1, 0, 3).AbsDiff(new Gray(0.0)).Convert<Gray, byte>().ThresholdBinary(new Gray(50), new Gray(255));
  17.             Mat SE = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(10, 2), new Point(-1, -1));
  18.             sobel = sobel.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Dilate, SE, new Point(-1, -1), 1, Emgu.CV.CvEnum.BorderType.Reflect, new MCvScalar(255));
  19.             Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint();
  20.             Mat m = new Mat();
  21.  
  22.             CvInvoke.FindContours(sobel, contours, m, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
  23.  
  24.             List<Rectangle> list = new List<Rectangle>();
  25.  
  26.             for (int i = 0; i < contours.Size; i++)
  27.             {
  28.                 Rectangle brect = CvInvoke.BoundingRectangle(contours[i]);
  29.  
  30.                 double ar = brect.Width / brect.Height;
  31.                 if (ar > 2 && brect.Width > 25 && brect.Height > 8 && brect.Height < 100)
  32.                 {
  33.                     list.Add(brect);
  34.                 }
  35.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement