Point2f[]转成InputArray
时间: 2023-09-18 16:08:04 浏览: 121
在OpenCV中,可以通过 `cv::InputArray` 类型来表示输入的多种数据类型,包括数组、图像等。如果需要将 `Point2f` 类型的数组转换为 `InputArray`,可以使用下面的代码:
```cpp
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Point2f points[4] = { Point2f(0, 0), Point2f(100, 0), Point2f(100, 100), Point2f(0, 100) };
Mat mat_points(4, 1, CV_32FC2, points);
InputArray input_array(mat_points);
return 0;
}
```
上述代码中,`Point2f` 数组 `points` 中包含了 4 个点,这些点将被转换为 `Mat` 类型的矩阵 `mat_points`。在转换时,需要指定矩阵的行数、列数、元素类型和数据指针,其中 `CV_32FC2` 表示矩阵的每个元素包含两个 32 位浮点数。最后,使用 `InputArray` 构造函数将 `mat_points` 转换为 `InputArray` 类型的对象 `input_array`。