c# - 将openCV的vector<Point2f>转换为C#的Collections::Generic::List<Windows::Point>

标签 c# c++ generics opencv

我想在我的 C++ 项目中将 OpenCV 中的点 vector ( vector )转换为 C# 点列表(Collections::Generic::List)。
我写了一些如下代码,但没有用:

vector<Point2f> oldPoints;
Collections::Generic::List<Windows::Point>^ points;
for (int i = 0; i < oldPoints.rows; i++)
 {
     points -> Add(Windows::Point(oldPoints.at<Point2f>(i,0).x,oldPoints.at<Point2f>(i,0).y));
 }

有人能帮帮我吗?我哪里做错了?
我找不到适合我的问题的答案;任何帮助或线索将不胜感激。

最佳答案

oldPointsstd::vector,但您可以像使用 cv::Mat 一样使用它。正确的代码是:

vector<Point2f> oldPoints;
Collections::Generic::List<Windows::Point>^ points 
    = gcnew Collections::Generic::List<Windows::Point>();
for (size_t i = 0; i < oldPoints.size(); i++)
{
    points->Add(Windows::Point(oldPoints[i].x, oldPoints[i].y));
}

关于c# - 将openCV的vector<Point2f>转换为C#的Collections::Generic::List<Windows::Point>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19543699/

相关文章:

c# - 什么时候使用 PreRender 而不是 PageLoad?

c# - Entity Framework - 如何查询多个表并选择要显示的列

c# - 最小化C#中的字符串长度

c++ - 弄清楚网络、十六进制和 ascii 如何交互

c# - 类型约束中的泛型

c# - 有人在 C# 应用程序中使用过 RE2 吗?

c++ - libmorph API 文档

c++ - 如何使用 yield_context 作为 resolver.async_resolve 的处理程序?

Java通用设计

java - 如何创建创建列表的方法的通用版本