Вот код:
Код: Выделить всё
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
CvInvoke.FindContours(binaryimg, contours, null, RetrType.Tree,
ChainApproxMethod.ChainApproxNone);
VectorOfPoint largestContour = null;
VectorOfPoint secondLargestContour = null;
double maxArea = 0;
double secondMaxArea = 0;
if (contours.Size < 2)
{
Console.WriteLine("Not enough contours found to detect both OD and ID.");
}
for (int i = 0; i < contours.Size; i++)
{
using (VectorOfPoint contour = contours[i])
{
double area = CvInvoke.ContourArea(contour);
if (area > maxArea)
{
secondMaxArea = maxArea;
secondLargestContour = largestContour;
maxArea = area;
largestContour = contour;
}
else if (area > secondMaxArea)
{
secondMaxArea = area;
secondLargestContour = contour;
}
}
}
if (largestContour != null && secondLargestContour !=null)
{
CircleF outerCircle = CvInvoke.MinEnclosingCircle(largestContour);
CircleF innerCircle = CvInvoke.MinEnclosingCircle(secondLargestContour);
}
[img]https://i.sstatic. net/otMelBA4.png[/img]
Вот исходное изображение:
[img]https://i.sstatic. net/8eQiu1TK.jpg[/img]
Подробнее здесь: https://stackoverflow.com/questions/789 ... each-other