Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing Polygons in OpenCV?

What am I doing wrong here?

vector <vector<Point> > contourElement;

for (int counter = 0; counter < contours -> size (); counter ++)
{   
    contourElement.push_back (contours -> at (counter));

    const Point *elementPoints [1] = {contourElement.at (0)};
    int numberOfPoints [] = {contourElement.at (0).size ()};

    fillPoly (contourMask, elementPoints, numberOfPoints, 1, Scalar (0, 0, 0), 8);

I keep getting an error on the const Point part. The compiler says

error: cannot convert 'std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >' to 'const cv::Point*' in initialization

What am I doing wrong? (PS: Obviously ignore the missing bracket at the end of the for loop due to this being only part of my code)

like image 785
fdh Avatar asked Nov 26 '11 20:11

fdh


1 Answers

Just for the record (and because the opencv docu is very sparse here) a more reduced snippet using the c++ API:

  std::vector<cv::Point> fillContSingle;
  [...]
  //add all points of the contour to the vector
  fillContSingle.push_back(cv::Point(x_coord,y_coord));
  [...]

  std::vector<std::vector<cv::Point> > fillContAll;
  //fill the single contour 
  //(one could add multiple other similar contours to the vector)
  fillContAll.push_back(fillContSingle);
  cv::fillPoly( image, fillContAll, cv::Scalar(128));
like image 199
Oliver Zendel Avatar answered Oct 26 '22 00:10

Oliver Zendel