输入图像,一条直线的两个点,获取线上边沿点,增加预处理滤波,基于opencvsharp4.6编写c#代码,生成新的函数 public static Point[] GetEdgePointsWithFilter(Mat image, Point lineP1, Point lineP2) {
时间: 2024-03-10 20:46:09 浏览: 82
下面是基于OpenCvSharp4.6的C#代码,实现了获取直线上边沿点并增加预处理滤波的功能:
```
using OpenCvSharp;
public static Point[] GetEdgePointsWithFilter(Mat image, Point lineP1, Point lineP2)
{
// 预处理滤波
Mat filteredImage = new Mat();
Cv2.GaussianBlur(image, filteredImage, new Size(3, 3), 0);
// 提取边缘
Mat edgeImage = new Mat();
Cv2.Canny(filteredImage, edgeImage, 100, 200);
// 获取直线上的所有像素点
LineIterator it = new LineIterator(edgeImage, lineP1, lineP2);
List<Point> points = new List<Point>();
while (!it.IsEnd)
{
points.Add(it.Pos());
it.Next();
}
return points.ToArray();
}
```
该函数接收一个Mat类型的图像和两个Point类型的点,返回一个Point数组,其中包含了直线上的所有边沿点。
该函数首先对输入图像进行预处理滤波,这里使用的是高斯滤波器,可以通过调整参数来改变滤波效果。然后,使用Canny算子提取图像边缘,接下来通过LineIterator遍历直线上的所有像素点,将其添加到一个List<Point>对象中。最后将List<Point>对象转换为Point[]数组并返回。
阅读全文
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)