Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

there might be no (vectorized) counterpart for what you're doing in the c++ api, but assuming a vector<Point> you could easily iterate over the contours:

Mat pixels; // initially empty
for (size_t i=0; i<contour.size(); i++) {
      Vec3b p = img.at<Vec3b>(contour[i]); // bgr
      //uchar p = img.at<uchar>(contour[i]); // grayscale
      pixels.push_back(p);
}

leaving you with a Mat with contour.size() rows and a single column

there might be no (vectorized) counterpart for what you're doing in the c++ api, but assuming your contour is a vector<Point> you could easily iterate over the contours:it:

Mat pixels; // initially empty
for (size_t i=0; i<contour.size(); i++) {
      Vec3b p = img.at<Vec3b>(contour[i]); // bgr
      //uchar p = img.at<uchar>(contour[i]); // grayscale
      pixels.push_back(p);
}

leaving you with a Mat with contour.size() rows and a single column

there might be no (vectorized) counterpart for what you're doing in the c++ api, but assuming your contour is a vector<Point> you could easily iterate over it:

Mat pixels; // initially empty
for (size_t i=0; i<contour.size(); i++) {
      Vec3b p = img.at<Vec3b>(contour[i]); // bgr
bgr image
      //uchar p = img.at<uchar>(contour[i]); // grayscale
grayscale version
      pixels.push_back(p);
}

leaving you with a Mat with contour.size() rows and a single column