1 | initial version |
if you just want to extract the pixel coordinates of the non-zero pixels, then you can use the findNonZero() (for some reason I cannot find it in the documentation) function:
cv::Mat binaryImage; // input, binary image
cv::Mat locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
and then access the coordinates by:
Point coordinate = locations.at<Point>(i);
Otherwise, you will have to do by yourself through looping the binary image and pushing the x, y point values of the non-zero pixels into a vector<point> structure. You can find many examples how to do that if you search into the web.
2 | No.2 Revision |
if you just want to extract the pixel coordinates of the non-zero pixels, then you can use the findNonZero() (for some reason I cannot find it in the documentation) function:
cv::Mat binaryImage; // input, binary image
cv::Mat locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
and then access the coordinates by:
Point coordinate = locations.at<Point>(i);
Otherwise, you will have to do by yourself through looping the binary image and pushing the x, y point values of the non-zero pixels into a vector<point> structure. You can find many examples how to do that if you search into the web.
edit ------------------------------------------------------------------------------------------------
it seems that passing coordinates straight forward to a vector<point> structure is also supported so you can just use:
cv::Mat binaryImage; // input, binary image
vector<Point> locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
3 | No.3 Revision |
if you just want to extract the pixel coordinates of the non-zero pixels, then you can use the findNonZero() (for some reason I cannot find it in the documentation) function:
cv::Mat binaryImage; // input, binary image
cv::Mat locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
and then access the coordinates by:
Point coordinate = locations.at<Point>(i);
Otherwise, you will have to do it by yourself through looping the binary image and pushing the x, y point values of the non-zero pixels into a vector<point> structure. You can find many examples how to do that if you search into the web.
edit ------------------------------------------------------------------------------------------------
it seems that passing coordinates straight forward to a vector<point> structure is also supported so you can just use:
cv::Mat binaryImage; // input, binary image
vector<Point> locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
4 | No.4 Revision |
if you just want to extract the pixel coordinates of the non-zero pixels, then you can use the findNonZero() (for some reason I cannot find it in the documentation) function:
cv::Mat binaryImage; // input, binary image
cv::Mat locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);
and then access the coordinates by:
Point coordinate = locations.at<Point>(i);
Otherwise, you will have to do it by yourself through looping the binary image and pushing the x, y point values of the non-zero pixels into a vector<point> structure. You can find many examples how to do that if you search into the web.
edit ------------------------------------------------------------------------------------------------
it seems that passing coordinates straight forward to a vector<point> structure is also supported from the findNonZero() function, so you can just use:
cv::Mat binaryImage; // input, binary image
vector<Point> locations; // output, locations of non-zero pixels
cv::findNonZero(binaryImage, locations);