Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mat frame = _capture.QueryFrame();
- //CvInvoke.Resize(frame, frame, pictureBox1.Size);
- Image<Bgr, Byte> img = frame.ToImage<Bgr, Byte>();
- Image<Gray, Byte> img1 = frame.ToImage<Gray, Byte>();
- Image<Gray, Byte> grayOriginal = img1.PyrDown();
- Image<Gray, Byte> grayOutput = grayOriginal.Clone();
- pictureBox2.Image = img1.ToBitmap(pictureBox1.Width, pictureBox1.Height);
- //img1 = img1.ThresholdBinary(new Gray(slider), new Gray(255));
- double cannyThreshold = 180.0;
- double circleAccumulatorThreshold = 120;
- double cannyThresholdLinking = 120.0;
- VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
- var cannyGray = grayOriginal.SmoothGaussian(5).Canny(cannyThreshold, cannyThresholdLinking);
- CvInvoke.FindContours(cannyGray, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
- foreach (var contour in contours.ToArrayOfArray())
- {
- VectorOfPoint poly = new VectorOfPoint();
- CvInvoke.ApproxPolyDP(new VectorOfPoint(contour), poly, 15, true);
- double area = CvInvoke.ContourArea(poly);
- if (area > 200 && area < 0.9 * grayOriginal.Width * grayOriginal.Height)
- {
- grayOutput.FillConvexPoly(poly.ToArray(), new Gray(255));
- }
- }
- CircleF[] circles = CvInvoke.HoughCircles(grayOriginal, HoughType.Gradient, 2.0, 20.0, cannyThreshold, circleAccumulatorThreshold, 5);
- int i = 0;
- foreach (var circle in circles)
- {
- grayOutput.Draw(circle, new Gray(200), -1);
- }
- pictureBox1.Image = grayOutput.ToBitmap(pictureBox1.Width, pictureBox1.Height);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement