去除定位点必须为四边形的筛选条件

This commit is contained in:
强 杨 2023-11-16 14:37:28 +08:00
parent dc35751d35
commit 163c306dbd
1 changed files with 17 additions and 5 deletions

View File

@ -430,6 +430,8 @@ public class CommonUse
// continue; // continue;
//} //}
//ShowMatWaitKey("dingweidian", DrawContours(mat, new VectorOfVectorOfPoint(contours[i])), 0.6);
Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);//外接矩形 Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);//外接矩形
Mat temp = new Mat(mat, rect);//提取ROI矩形区域 Mat temp = new Mat(mat, rect);//提取ROI矩形区域
int pxNums = CvInvoke.CountNonZero(temp);//计算图像内非零像素个数 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 / 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 = ((rect.Width > 3 && rect.Height > 2) && (area > 80 && area <= 15000));
//bool bo = pxNums > 130 && pxNums < 300; //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) if (bo)
{ {
selected_contours.Push(contours[i]); selected_contours.Push(contours[i]);
@ -1403,7 +1409,7 @@ public class CommonUse
Mat mat_color = new Mat(); Mat mat_color = new Mat();
CvInvoke.CvtColor(mat, mat_color, Emgu.CV.CvEnum.ColorConversion.Gray2Bgr); 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; return mat_color;
} }
@ -1501,8 +1507,14 @@ public class CommonUse
/// <param name="zoomRatio"></param> /// <param name="zoomRatio"></param>
public void ShowMatWaitKey(string title, Mat mat, double zoomRatio) public void ShowMatWaitKey(string title, Mat mat, double zoomRatio)
{ {
CvInvoke.Resize(mat, mat, new Size(), zoomRatio, zoomRatio, Inter.Cubic); if (!System.Diagnostics.Debugger.IsAttached)
CvInvoke.Imshow(title, mat); {
return;
}
var result = new Mat();
CvInvoke.Resize(mat, result, new Size(), zoomRatio, zoomRatio, Inter.Cubic);
CvInvoke.Imshow(title, result);
CvInvoke.WaitKey(0); CvInvoke.WaitKey(0);
} }