From 0b560105363e054f3a299435a9d19697094cc81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= Date: Thu, 30 Apr 2026 09:22:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=B0=94=E6=B3=A1=E7=AD=9B?= =?UTF-8?q?=E9=80=89=E9=80=BB=E8=BE=91=EF=BC=9A=E6=8C=89=E7=85=A7=E9=9D=A2?= =?UTF-8?q?=E7=A7=AF=E7=AD=9B=E9=80=89=EF=BC=8C=E5=8E=BB=E9=99=A4=E5=B0=8F?= =?UTF-8?q?=E4=BA=8E=E8=AE=BE=E5=AE=9A=E9=9D=A2=E7=A7=AF=E7=9A=84=E6=B0=94?= =?UTF-8?q?=E6=B3=A1=E9=87=8D=E6=96=B0=E8=AE=A1=E7=AE=97=E7=A9=BA=E9=9A=99?= =?UTF-8?q?=E7=8E=87=E6=9B=B4=E6=96=B0=E7=BB=93=E6=9E=9C=E5=9B=BE=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../检测分析/BgaVoidRateProcessor.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/XP.ImageProcessing.Processors/检测分析/BgaVoidRateProcessor.cs b/XP.ImageProcessing.Processors/检测分析/BgaVoidRateProcessor.cs index d78fae9..450d0f1 100644 --- a/XP.ImageProcessing.Processors/检测分析/BgaVoidRateProcessor.cs +++ b/XP.ImageProcessing.Processors/检测分析/BgaVoidRateProcessor.cs @@ -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;