mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
More contour utility
This commit is contained in:
@@ -108,6 +108,33 @@ namespace UVtools.Core.EmguCV
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets contours that are positive pixels and group them by areas
|
||||
/// Only compatible with Tree type of contour detection
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<VectorOfVectorOfPoint> GetPositiveContoursInGroups(VectorOfVectorOfPoint contours, int[,] hierarchy)
|
||||
{
|
||||
var result = new List<VectorOfVectorOfPoint>();
|
||||
var vectorSize = contours.Size;
|
||||
var processedContours = new bool[vectorSize];
|
||||
for (int i = 0; i < vectorSize; i++)
|
||||
{
|
||||
if (processedContours[i]) continue;
|
||||
processedContours[i] = true;
|
||||
var index = result.Count;
|
||||
result.Add(new VectorOfVectorOfPoint(contours[i]));
|
||||
for (int n = i + 1; n < vectorSize; n++)
|
||||
{
|
||||
if (processedContours[n] || hierarchy[n, EmguContour.HierarchyParent] != i) continue;
|
||||
processedContours[n] = true;
|
||||
result[index].Push(contours[n]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets contours inside contours that are black pixels and group them by areas
|
||||
/// Only compatible with Tree type of contour detection
|
||||
@@ -123,12 +150,13 @@ namespace UVtools.Core.EmguCV
|
||||
if (processedContours[i]) continue;
|
||||
processedContours[i] = true;
|
||||
if (hierarchy[i, EmguContour.HierarchyParent] == -1) continue;
|
||||
var index = result.Count;
|
||||
result.Add(new VectorOfVectorOfPoint(contours[i]));
|
||||
for (int n = i + 1; n < vectorSize; n++)
|
||||
{
|
||||
if (processedContours[n] || hierarchy[n, EmguContour.HierarchyParent] != i) continue;
|
||||
processedContours[n] = true;
|
||||
result[^1].Push(contours[n]);
|
||||
result[index].Push(contours[n]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1214,22 +1214,7 @@ namespace UVtools.WPF
|
||||
using var vec = EmguContours.GetContoursInside(LayerCache.LayerContours, LayerCache.LayerContourHierarchy, operation.Location);
|
||||
if (vec.Size > 0) CvInvoke.DrawContours(LayerCache.ImageBgr, vec, -1, new MCvScalar(color.B, color.G, color.R), -1);
|
||||
|
||||
/*var hollowGroups = new List<VectorOfVectorOfPoint>();
|
||||
var processedContours = new bool[LayerCache.LayerContours.Size];
|
||||
for (int i = 0; i < LayerCache.LayerContours.Size; i++)
|
||||
{
|
||||
if(processedContours[i]) continue;
|
||||
processedContours[i] = true;
|
||||
if (LayerCache.LayerContourHierarchy[i, EmguContour.HierarchyParent] == -1) continue;
|
||||
hollowGroups.Add(new VectorOfVectorOfPoint(LayerCache.LayerContours[i]));
|
||||
for (int n = i + 1; n < LayerCache.LayerContours.Size; n++)
|
||||
{
|
||||
if (processedContours[n] || LayerCache.LayerContourHierarchy[n, EmguContour.HierarchyParent] != i) continue;
|
||||
processedContours[n] = true;
|
||||
hollowGroups[^1].Push(LayerCache.LayerContours[n]);
|
||||
}
|
||||
|
||||
}
|
||||
/*var hollowGroups = EmguContours.GetPositiveContoursInGroups(LayerCache.LayerContours, LayerCache.LayerContourHierarchy);
|
||||
|
||||
foreach (var vec in hollowGroups)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user