Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Welcome on board @KBH !

Supposing you are talking about closed contours, you can create masks for your contours with drawContours using thickness=cv::FILLED to fill the area bounded by the contours.

cv::findContours(edges,contours,....
cv::Mat mask = cv::zeros(edges.Size(),cv::CV_8UC1);
for(size_t i;i<contours.size();i++)
{
    cv::drawContours( mask, contours, i, cv::Scalar(255,255,255), cv::FILLED);
}

Then, if you need the index points of INSIDE areas you can use findNonZero on your mask

std::vector<cv::Point> insidePoints;   // output, locations of non-zero pixels
cv::findNonZero(mask, locations);

finally, if you need the index points of OUTSIDE areas you can invert your mask than repeat findNonZero

mask = 255-mask;
std::vector<cv::Point> outsidePoints;
cv::findNonZero(mask, outsidePoints);