在我进行一些图像处理并应用蒙版后,我得到了我想要的。我可以在“裁剪”的 imshow 结果中清楚地看到图像中间有灰色像素。我正在尝试获取最大像素值位置。我检查了crop.channels(),它返回1。
Mat mask = drawing2;
drawContours(mask, contours, -1, Scalar(255), CV_FILLED);
Mat dist;
distanceTransform( cannyInv, dist, CV_DIST_L2, 3 );
normalize(dist,dist,0.0,1.0,NORM_MINMAX);
Mat crop;
dist.copyTo(crop, mask);
cout << "max.. "<< *std::max_element(crop.begin<double>(),crop.end<double>()) <<endl;
返回最大值.. 4.25593e-08
for(int y = 0; y < crop.rows; y++)
{
for(int x = 0; x < crop.cols; x++)
{
if (crop.at<unsigned char>(x,y) > 0){
cout << "X........"<<x<<" Y......"<<y<< " = "<<crop.at<unsigned char>(x,y) <<endl;
}
}
}
输出是:
X........604 Y......479 = ¿
X........607 Y......479 =
X........610 Y......479 = ¿
请帮帮我
PD:我知道有类似的问题。但这是具体问题。