【发布时间】:2015-05-29 03:17:57
【问题描述】:
我有一张经过裁剪的硬币图像。我已经应用了面具,所以我可以专注于硬币本身。接下来是我要计算这枚硬币的像素数。我已经阅读过类似的帖子,但它们似乎对我不起作用。
这是原图: http://s30.postimg.org/eeh3lp99d/IMG_20150414_121300.jpg
和裁剪的硬币: http://s3.postimg.org/4k2pdst73/cropped.png
到目前为止,这是我的代码:
//get the number of pixels of the coin
//STEP 1: CROP THE COIN
//get the Rect containing he circl
Rect rectCircle(center.x - radius, center.y - radius, radius * 2, radius * 2); //obtain the image ROI:
Mat roi(src_gray, rectCircle);
//make a black mask, same size:
Mat mask(roi.size(), roi.type(), Scalar::all(0));
//with a white,filled circle in it:
circle(mask, Point(radius, radius), radius, Scalar::all(255), -1);
//combine roi and mask:
cv::Mat coin_cropped = roi & mask;
如何计算裁剪硬币的像素数?
【问题讨论】:
-
记得贴出你目前的代码
-
这是我目前所拥有的......
//get the number of pixels of the coin //STEP 1: CROP THE COIN //get the Rect containing he circl Rect rectCircle(center.x - radius, center.y - radius, radius * 2, radius * 2); //obtain the image ROI: Mat roi(src_gray, rectCircle); //make a black mask, same size: Mat mask(roi.size(), roi.type(), Scalar::all(0)); //with a white,filled circle in it: circle(mask, Point(radius, radius), radius, Scalar::all(255), -1); //combine roi and mask: cv::Mat coin_cropped = roi & mask; -
在你的面具上使用 cv::countNonZero 函数
-
@Micka,我在哪里插入 cv::countNonZero?太感谢了。我真是个菜鸟。
标签: opencv pixels image-size roi