2012-04-05 2 views
1

에 변환합니다. vector<vector<Point> > X가 있는데, CvArr*을 입력하는 cvConvexityDefects 함수에 전달해야합니다.벡터 <벡터 <Point>> X를 IplImage * 또는 cv :: Mat *

나는 이미 주제 Convexity defects C++ OpenCv을 읽었습니다. 나는 vector<Point>하는 선체 매개 변수를 가지고 있기 때문에

vector<Point>& contour, vector<int>& hull, vector<Point>& convexDefects 

내가 솔루션이 동작하지 않습니다와 나는 vector<int>에 변환하는 방법을 알고하지 않습니다 그것은 입력에서 이러한 변수를합니다.

그래서 두 가지 질문이 있습니다. :)

vector<vector<Point> >vector<int>으로 변환하려면 어떻게해야하나요? ! 미리

덕분에, 사용 std::for_each

+0

OpenCV의 어떤 버전 사용 할 ? – Alex

+0

2.3.1, 마지막 하나 ... 사이트에서 다운로드 http://opencv.willowgarage.com/wiki/ –

답변

0

: 좋은 일을하고 축적 객체 :

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; 
} 
+0

oyu 너무 감사합니다 :) 완벽 해! 그냥 한가지 : 포인트 객체 (단지 point.x와 point.y)에 point.z 변수가 없기 때문에 m_accumulated.push_back (point.z) 라인을 주석 처리합니다. 다시 한 번 고마워요 –

+0

@MarcoMaisto OpenCV를 모르겠습니다. 그래서 추측이었습니다. 고쳤다. –

관련 문제