there is a built-in function for this cv :: findNonZero
Returns a list of non-zero pixel locations.
(, , cv::threshold(), cv::compare(), >, == ..) cv::Mat std::vector<cv::Point>
:
cv::Mat binaryImage;
cv::Mat locations;
cv::findNonZero(binaryImage, locations);
Point pnt = locations.at<Point>(i);
cv::Mat binaryImage;
vector<Point> locations;
cv::findNonZero(binaryImage, locations);
Point pnt = locations[i];