Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void CannyEdgeDetection()
- {
- Image<Gray, Byte> grayImage = new Image<Gray, byte>(imageBox1.Image.Bitmap);
- var blurredImage = grayImage.SmoothGaussian(5, 5, 0, 0);
- var cannyImage = new UMat();
- CvInvoke.Canny(blurredImage, cannyImage, 50, 150);
- Image<Gray, Byte> showCanny = new Image<Gray, byte>(cannyImage.Bitmap);
- imageBox4.Image = showCanny;
- }
- private void CannyOCR()
- {
- //sobel
- Image<Bgr, Byte> img = new Image<Bgr, byte>(imageBox1.Image.Bitmap);
- 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));
- Mat SE = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(10, 2), new Point(-1, -1));
- sobel = sobel.MorphologyEx(Emgu.CV.CvEnum.MorphOp.Dilate, SE, new Point(-1, -1), 1, Emgu.CV.CvEnum.BorderType.Reflect, new MCvScalar(255));
- Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint();
- Mat m = new Mat();
- CvInvoke.FindContours(sobel, contours, m, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
- List<Rectangle> list = new List<Rectangle>();
- for (int i = 0; i < contours.Size; i++)
- {
- Rectangle brect = CvInvoke.BoundingRectangle(contours[i]);
- double ar = brect.Width / brect.Height;
- if (ar > 2 && brect.Width > 25 && brect.Height > 8 && brect.Height < 100)
- {
- list.Add(brect);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement