Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Mat frame = _capture.QueryFrame();
  2. //CvInvoke.Resize(frame, frame, pictureBox1.Size);
  3. Image<Bgr, Byte> img = frame.ToImage<Bgr, Byte>();
  4. Image<Gray, Byte> img1 = frame.ToImage<Gray, Byte>();
  5. Image<Gray, Byte> grayOriginal = img1.PyrDown();
  6. Image<Gray, Byte> grayOutput = grayOriginal.Clone();
  7.  
  8. pictureBox2.Image = img1.ToBitmap(pictureBox1.Width, pictureBox1.Height);
  9.  
  10.  
  11. //img1 = img1.ThresholdBinary(new Gray(slider), new Gray(255));
  12.  
  13. double cannyThreshold = 180.0;
  14. double circleAccumulatorThreshold = 120;
  15. double cannyThresholdLinking = 120.0;
  16.  
  17. VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
  18. var cannyGray = grayOriginal.SmoothGaussian(5).Canny(cannyThreshold, cannyThresholdLinking);
  19. CvInvoke.FindContours(cannyGray, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
  20.  
  21.  
  22. foreach (var contour in contours.ToArrayOfArray())
  23. {
  24. VectorOfPoint poly = new VectorOfPoint();
  25. CvInvoke.ApproxPolyDP(new VectorOfPoint(contour), poly, 15, true);
  26.  
  27. double area = CvInvoke.ContourArea(poly);
  28.  
  29. if (area > 200 && area < 0.9 * grayOriginal.Width * grayOriginal.Height)
  30. {
  31. grayOutput.FillConvexPoly(poly.ToArray(), new Gray(255));
  32. }
  33. }
  34.  
  35. CircleF[] circles = CvInvoke.HoughCircles(grayOriginal, HoughType.Gradient, 2.0, 20.0, cannyThreshold, circleAccumulatorThreshold, 5);
  36. int i = 0;
  37. foreach (var circle in circles)
  38. {
  39. grayOutput.Draw(circle, new Gray(200), -1);
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. pictureBox1.Image = grayOutput.ToBitmap(pictureBox1.Width, pictureBox1.Height);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement