【问题标题】:printing elements of a vector<Point2i>打印 vector<Point2i> 的元素
【发布时间】:2016-04-19 16:49:17
【问题描述】:

如果我有一个向量并像这样初始化它。如何分别访问点的第一部分和第二部分。

vector<Point2i> cent_i(1); // how do i initialize with a point like (1,2 )
cent_i[0][0] = (floor( s.width/2)); //TRYING TO change the points
cent_i[0][1] = (floor( s.height/2));

我不知道我这样做是否正确

【问题讨论】:

    标签: c++ opencv vector


    【解决方案1】:

    可以直接在构造函数中初始化点,如:

    vector<Point> pts {Point(1,2), Point(3,4), Point(5,6)};
    

    或:

    vector<Point> pts {{1,2}, {3,4}, {5,6}};
    

    您可以访问向量的第 i 个Point,例如:

    pts[i].x = ...
    pts[i].y = ...
    

    请记住,Point 只是 typedefPoint2i

    【讨论】:

      【解决方案2】:

      基于来自 OpenCv 的 Documentation。以下是您如何索引名为 Point2istd::vectorpoints

      points[0].x, points[0].y, points[1].x, points[1].y, ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-25
        • 1970-01-01
        • 2016-04-26
        • 2014-12-29
        • 1970-01-01
        • 2011-03-23
        相关资源
        最近更新 更多