已合并 PR 59: 更改气泡筛选逻辑
1.加载新图像时会自动清除旧的测量结果、叠加层和ROI 2.更改气泡筛选逻辑:按照面积筛选,去除小于设定面积的气泡重新计算空隙率更新结果图像
This commit is contained in:
@@ -333,14 +333,13 @@ public class BgaVoidRateProcessor : ImageProcessorBase
|
||||
}
|
||||
|
||||
int voidPixels = CvInvoke.CountNonZero(voidImg);
|
||||
bga.VoidPixels = voidPixels;
|
||||
bga.VoidRate = bgaPixels > 0 ? (double)voidPixels / bgaPixels * 100.0 : 0;
|
||||
|
||||
// 检测每个气泡的轮廓
|
||||
using var contours = new VectorOfVectorOfPoint();
|
||||
using var hierarchy = new Mat();
|
||||
CvInvoke.FindContours(voidImg, contours, hierarchy, RetrType.External, ChainApproxMethod.ChainApproxSimple);
|
||||
|
||||
int filteredVoidArea = 0;
|
||||
for (int i = 0; i < contours.Size; i++)
|
||||
{
|
||||
double area = CvInvoke.ContourArea(contours[i]);
|
||||
@@ -349,6 +348,7 @@ public class BgaVoidRateProcessor : ImageProcessorBase
|
||||
var moments = CvInvoke.Moments(contours[i]);
|
||||
if (moments.M00 < 1) continue;
|
||||
|
||||
filteredVoidArea += (int)Math.Round(area);
|
||||
bga.Voids.Add(new VoidInfo
|
||||
{
|
||||
Index = bga.Voids.Count + 1,
|
||||
@@ -361,6 +361,10 @@ public class BgaVoidRateProcessor : ImageProcessorBase
|
||||
});
|
||||
}
|
||||
|
||||
// 空隙率基于过滤后的轮廓面积计算
|
||||
bga.VoidPixels = filteredVoidArea;
|
||||
bga.VoidRate = bgaPixels > 0 ? (double)filteredVoidArea / bgaPixels * 100.0 : 0;
|
||||
|
||||
// 按面积从大到小排序
|
||||
bga.Voids.Sort((a, b) => b.Area.CompareTo(a.Area));
|
||||
for (int i = 0; i < bga.Voids.Count; i++) bga.Voids[i].Index = i + 1;
|
||||
|
||||
@@ -123,7 +123,6 @@ namespace XP.ImageProcessing.RoiControl.Controls
|
||||
var control = (PolygonRoiCanvas)d;
|
||||
if (e.NewValue is BitmapSource bitmap)
|
||||
{
|
||||
// 使用像素尺寸,避免 DPI 不同导致 DIP 尺寸与实际像素不一致
|
||||
control.CanvasWidth = bitmap.PixelWidth;
|
||||
control.CanvasHeight = bitmap.PixelHeight;
|
||||
control.ResetView();
|
||||
@@ -135,6 +134,11 @@ namespace XP.ImageProcessing.RoiControl.Controls
|
||||
control.ResetView();
|
||||
}
|
||||
|
||||
// 图像切换时清除测量、叠加层和ROI
|
||||
control.ClearMeasurements();
|
||||
control.ROIItems?.Clear();
|
||||
control.SelectedROI = null;
|
||||
|
||||
// 图像尺寸变化后刷新十字线
|
||||
if (control.ShowCrosshair)
|
||||
control.AddCrosshair();
|
||||
|
||||
Reference in New Issue
Block a user