dIrX 过滤X方向点的间距差值 private static List<Point2f> FilterPoints(Mat resultImage, List<Point2f> points, double tolerance,bool dIrX) { var filteredPoints = new List<Point2f>(); foreach (var currentPoint in points) { bool isUnique = points .Where(p => p != currentPoint) .All(comparePoint => ((currentPoint.X - comparePoint.X) * (currentPoint.X - comparePoint.X) + (currentPoint.Y - comparePoint.Y) * (currentPoint.Y - comparePoint.Y)) >= tolerance * tolerance); if (isUnique) { filteredPoints.Add(currentPoint); drawCross(resultImage, new Point2f(currentPoint.X , currentPoint.Y ), Scalar.Red, 5, 1); } } return filteredPoints; } 基于opencvsharp4.5编写c#代码,生成新的函数
时间: 2024-02-14 22:10:50 浏览: 111
可以考虑编写一个类似于上述代码的函数,以实现在Y方向上过滤点的间距差值。代码如下:
```
private static List<Point2f> FilterPointsY(Mat resultImage, List<Point2f> points, double tolerance)
{
var filteredPoints = new List<Point2f>();
foreach (var currentPoint in points)
{
bool isUnique = points
.Where(p => p != currentPoint)
.All(comparePoint => ((currentPoint.X - comparePoint.X) * (currentPoint.X - comparePoint.X) + (currentPoint.Y - comparePoint.Y) * (currentPoint.Y - comparePoint.Y)) >= tolerance * tolerance);
if (isUnique)
{
filteredPoints.Add(currentPoint);
drawCross(resultImage, new Point2f(currentPoint.X, currentPoint.Y), Scalar.Red, 5, 1);
}
}
return filteredPoints;
}
```
该函数的作用是对输入的点集进行过滤,仅保留Y方向上间距大于等于指定容差值的点。其中,参数`points`表示输入的点集,`tolerance`表示容差值,`resultImage`表示需要在其上绘制筛选后的点的图像。函数返回经过过滤后的点集。
阅读全文