Y方向上过滤点的间距差值或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; }
时间: 2024-03-10 19:47:06 浏览: 94
可以将两个函数合并为一个,使其可以根据传入的参数选择在X方向或Y方向进行过滤。代码如下:
```
private static List<Point2f> FilterPoints(Mat resultImage, List<Point2f> points, double tolerance, bool filterX)
{
var filteredPoints = new List<Point2f>();
foreach (var currentPoint in points)
{
bool isUnique = points
.Where(p => p != currentPoint)
.All(comparePoint =>
{
if (filterX)
{
return ((currentPoint.X - comparePoint.X) * (currentPoint.X - comparePoint.X) + (currentPoint.Y - comparePoint.Y) * (currentPoint.Y - comparePoint.Y)) >= tolerance * tolerance;
}
else
{
return ((currentPoint.Y - comparePoint.Y) * (currentPoint.Y - comparePoint.Y) + (currentPoint.X - comparePoint.X) * (currentPoint.X - comparePoint.X)) >= tolerance * tolerance;
}
});
if (isUnique)
{
filteredPoints.Add(currentPoint);
drawCross(resultImage, new Point2f(currentPoint.X, currentPoint.Y), Scalar.Red, 5, 1);
}
}
return filteredPoints;
}
```
该函数的参数`filterX`表示是否在X方向进行过滤,若为`true`,则在X方向进行过滤,否则在Y方向进行过滤。函数根据传入的参数进行判断并执行相应的过滤操作。
阅读全文