OpenCvSharp List<Point2d> points = new List<Point2d>();转换成InputArray points
时间: 2023-12-19 11:07:30 浏览: 26
您可以使用 `InputArray.Create` 方法将 `List<Point2d>` 转换为 `InputArray`,如下所示:
```csharp
List<Point2d> points = new List<Point2d>();
// 填充 points...
// 将 points 转换为 InputArray
InputArray pointsArray = InputArray.Create(points.ToArray());
```
或者,如果您正在使用 `Mat`,则可以使用 `MatOfPoint2d.FromList` 方法直接将 `List<Point2d>` 转换为 `MatOfPoint2d`,如下所示:
```csharp
List<Point2d> points = new List<Point2d>();
// 填充 points...
// 将 points 转换为 MatOfPoint2d
MatOfPoint2d pointsMat = MatOfPoint2d.FromList(points);
```
无论哪种方法,您都可以使用 `InputArray` 或 `MatOfPoint2d` 作为参数传递给 OpenCV 函数。
相关问题
List<Point2d> points = new List<Point2d>();转换成InputArray points
可以使用`InputArray`的构造函数将`List<Point2d>`转换为`InputArray`,如下所示:
```c++
std::vector<Point2d> points; // 声明一个 vector 存储 Point2d 类型的数据
cv::InputArray inputArray(points); // 将 vector 转换为 InputArray
```
需要注意的是,`InputArray`只是对输入数据的一种封装方式,并不会改变数据本身的类型和内容。因此,在将`List<Point2d>`转换为`InputArray`后,仍然需要根据具体需求使用相应的函数进行处理。
OpenCvSharp4.6 (List<Point2f> points,转换成 InputArray
同样地,要将 List<Point2f> 转换成 InputArray,可以使用 MatOfPoint2f 类。具体的实现代码如下:
```csharp
List<Point2f> points = new List<Point2f>();
// 假设 points 中已经有一些数据
MatOfPoint2f mat = new MatOfPoint2f();
mat.FromList(points);
InputArray inputArray = mat;
```
但需要注意的是,OpenCvSharp4.6 中的 MatOfPoint2f 类已经不再提供 FromList 方法,所以需要使用其构造函数来初始化 MatOfPoint2f 对象。具体实现代码如下:
```csharp
List<Point2f> points = new List<Point2f>();
// 假设 points 中已经有一些数据
MatOfPoint2f mat = new MatOfPoint2f(points.ToArray());
InputArray inputArray = mat;
```
这样就可以将 List<Point2f> 转换成 InputArray 了。