本文整理匯總了C#中System.Drawing.Image.FindContours方法的典型用法代碼示例。如果您正苦於以下問題:C# Image.FindContours方法的具體用法?C# Image.FindContours怎麽用?C# Image.FindContours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Image
的用法示例。
在下文中一共展示了Image.FindContours方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: FindRectangles
private static Rectangle[] FindRectangles(Image<Gray, byte> gray)
{
var result = new List<Rectangle>();
for (var contour = gray.FindContours(); contour != null; contour = contour.HNext) {
var rect = contour.BoundingRectangle;
result.Add(new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
// result.Add(rect);
}
return result.ToArray();
}
示例2: extractPaperContours
/// <summary>
/// Extract paper contours from an HSV image.
/// </summary>
/// <param name="binaryImage">HSV image to extract paper contours from.</param>
/// <returns>Paper contours extracted.</returns>
public List<Contour<Point>> extractPaperContours(Image<Gray, byte> binaryImage)
{
List<Contour<Point>> paperContours = new List<Contour<Point>>();
using(MemStorage storage = new MemStorage())
{
for (Contour<Point> contour = binaryImage.FindContours(); contour != null; contour = contour.HNext)
{
if((contour.BoundingRectangle.Height * contour.BoundingRectangle.Width) >= (binaryImage.Height * binaryImage.Width * CONTOUR_AREA_PERCENTAGE_THRESHOLD))
{
paperContours.Add(contour);
}
}
}
return paperContours;
}