From 163c306dbd249d6aa69b6dd957060e247692b1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=BA=20=E6=9D=A8?= Date: Thu, 16 Nov 2023 14:37:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=AE=9A=E4=BD=8D=E7=82=B9?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E4=B8=BA=E5=9B=9B=E8=BE=B9=E5=BD=A2=E7=9A=84?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/CommonUse.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs index 1f7e572..57d260f 100644 --- a/App_Code/CommonUse.cs +++ b/App_Code/CommonUse.cs @@ -197,7 +197,7 @@ public class CommonUse } catch { - message = GetPostionString(i)+"未找到定位点"; + message = GetPostionString(i) + "未找到定位点"; xielv = -100; return null; } @@ -430,6 +430,8 @@ public class CommonUse // continue; //} + //ShowMatWaitKey("dingweidian", DrawContours(mat, new VectorOfVectorOfPoint(contours[i])), 0.6); + Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);//外接矩形 Mat temp = new Mat(mat, rect);//提取ROI矩形区域 int pxNums = CvInvoke.CountNonZero(temp);//计算图像内非零像素个数 @@ -444,7 +446,11 @@ public class CommonUse // bool bo = (rect.Width / rect.Height >= ratio && (rect.Width > 3 && rect.Height > 2) && (area > 200 && area <= 4500)); //bool bo = ((rect.Width > 3 && rect.Height > 2) && (area > 80 && area <= 15000)); //bool bo = pxNums > 130 && pxNums < 300; - bool bo = (approx_curve.Size == 4 && CvInvoke.IsContourConvex(approx_curve) && (rect.Width > 10 && rect.Height > 10) && (area > 350 && area < 2000) && (rect.Width < 50 && rect.Height < 50) && pxNums > 200); + bool bo = (CvInvoke.IsContourConvex(approx_curve) + && (rect.Width > 10 && rect.Height > 10) + && (area > 200 && area < 2000) + && (rect.Width < 50 && rect.Height < 50) + && pxNums > 200); if (bo) { selected_contours.Push(contours[i]); @@ -1403,7 +1409,7 @@ public class CommonUse Mat mat_color = new Mat(); CvInvoke.CvtColor(mat, mat_color, Emgu.CV.CvEnum.ColorConversion.Gray2Bgr); - CvInvoke.DrawContours(mat_color, contours, -1, new MCvScalar(255, 0, 0), 2); + CvInvoke.DrawContours(mat_color, contours, -1, new MCvScalar(0, 0, 255), 2); return mat_color; } @@ -1501,8 +1507,14 @@ public class CommonUse /// public void ShowMatWaitKey(string title, Mat mat, double zoomRatio) { - CvInvoke.Resize(mat, mat, new Size(), zoomRatio, zoomRatio, Inter.Cubic); - CvInvoke.Imshow(title, mat); + if (!System.Diagnostics.Debugger.IsAttached) + { + return; + } + + var result = new Mat(); + CvInvoke.Resize(mat, result, new Size(), zoomRatio, zoomRatio, Inter.Cubic); + CvInvoke.Imshow(title, result); CvInvoke.WaitKey(0); }