我有一个 vector<vector<Point> >
X 但我需要将它传递给函数 cvConvexityDefects
输入一个 CvArr*
.
我已经读过题目Convexity defects C++ OpenCv .它接受输入这些变量:
vector<Point>& contour, vector<int>& hull, vector<Point>& convexDefects
我无法使解决方案起作用,因为我的船体参数是 vector<Point>
我不知道如何在 vector<int>
中转换它.
那么现在有两个问题! :)
如何转换 vector<vector<Point> >
进入 vector<int>
?
提前致谢,祝您有美好的一天!:)
最佳答案
使用 std::for_each
和一个累积对象:
class AccumulatePoints
{
public:
AccumulatePoints(std::vector<int>& accumulated)
: m_accumulated(accumulated)
{
}
void operator()(const std::vector<Point>& points)
{
std::for_each(points.begin(), points.end(), *this);
}
void operator()(const Point& point)
{
m_accumulated.push_back(point.x);
m_accumulated.push_back(point.y);
}
private:
std::vector<int>& m_accumulated;
};
这样使用:
int main()
{
std::vector<int> accumulated;
std::vector<std::vector<Point>> hull;
std::for_each(hull.begin(), hull.end(), AccumulatePoints(accumulated));
return 0;
}
关于c++ - 将 vector<vector<Point>> X 转换为 IplImage* 或 cv::Mat*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10027022/