【发布时间】:2016-04-30 22:36:43
【问题描述】:
在 OpenCV (C++) 中,我有一个黑白图像,其中一些形状看起来充满了白色 (255)。知道了这一点,我怎样才能得到这些对象在图像中的坐标点?我有兴趣获取所有白色像素坐标。
还有比这更干净的方法吗?
std::vector<int> coordinates_white; // will temporaly store the coordinates where "white" is found
for (int i = 0; i<img_size.height; i++) {
for (int j = 0; j<img_size.width; j++) {
if (img_tmp.at<int>(i,j)>250) {
coordinates_white.push_back(i);
coordinates_white.push_back(j);
}
}
}
// copy the coordinates into a matrix where each row represents a *(x,y)* pair
cv::Mat coordinates = cv::Mat(coordinates_white.size()/2,2,CV_32S,&coordinates_white.front());
【问题讨论】:
标签: c++ opencv matrix threshold