bool searchDir_left2right //从左往右找点 public void FindExtremePoint(Mat image, bool searchDir_left2right , ref List<Point2f> zeroPList) { if (image.Width == 0) { return;// throw new ArgumentNullException(nameof(image)); } // 预处理:中值滤波 Cv2.MedianBlur(image, image, 3); // 计算极值和位置 Point2f extremaLoc; double extremaVal; double minVal, maxVal; var criteria = new TermCriteria(CriteriaTypes.Eps | CriteriaTypes.Count, 20, 0.03); //MinMaxLoc(InputArray src, out double minVal, out double maxVal, out Point minLoc, out Point maxLoc, InputArray? mask = null); Cv2.MinMaxLoc(image, out minVal, out maxVal, out Point minLoc, out Point _); Point2f[] corners = new[] { new Point2f(minLoc.X, minLoc.Y) }; Cv2.CornerSubPix(image, corners, new Size(3, 3), new Size(-1, -1), criteria); extremaVal = minVal; extremaLoc = corners[0]; zeroPList.Add( extremaLoc); } 基于opencvsharp4.6编写c#代码,生成新的函数
时间: 2024-01-23 11:04:11 浏览: 142
以下是基于OpenCvSharp4.6编写的C#函数:
```
public void FindExtremePoint(Mat image, bool searchDir_left2right, ref List<Point2f> zeroPList)
{
if (image.Width == 0)
{
return;// throw new ArgumentNullException(nameof(image));
}
// 预处理:中值滤波
Cv2.MedianBlur(image, image, 3);
// 计算极值和位置
Point2f extremaLoc;
double extremaVal;
double minVal, maxVal;
var criteria = new TermCriteria(CriteriaTypes.Eps | CriteriaTypes.Count, 20, 0.03);
//MinMaxLoc(InputArray src, out double minVal, out double maxVal, out Point minLoc, out Point maxLoc, InputArray? mask = null);
Cv2.MinMaxLoc(image, out minVal, out maxVal, out Point minLoc, out Point _);
Point2f[] corners = new[] { new Point2f(minLoc.X, minLoc.Y) };
Cv2.CornerSubPix(image, corners, new Size(3, 3), new Size(-1, -1), criteria);
extremaVal = minVal;
extremaLoc = corners[0];
zeroPList.Add(extremaLoc);
}
```
此函数的作用是从输入的图像中查找极值点,并将其位置信息存储在一个列表中。函数的参数包括:
- image:输入的图像
- searchDir_left2right:一个bool值,表示是否从左往右查找点
- zeroPList:一个Point2f类型的列表,用于存储极值点的位置信息。
函数内部首先进行了中值滤波的预处理,然后使用MinMaxLoc函数查找图像中的最小值和最大值,并将最小值的位置信息存储在corners数组中。接着使用CornerSubPix函数对corners数组进行亚像素级别的精细化处理,得到最终的极值点位置信息extremaLoc。最后将extremaLoc加入到zeroPList列表中。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![text/plain](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)