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); }