【问题标题】:Getting ROI from a Circle/Point从圆/点获取 ROI
【发布时间】:2014-12-02 18:19:05
【问题描述】:

我在图像中有两个点,左眼中心 (X, Y) 和右眼中心 (X, Y)。我使用cv::circle 在双眼周围画了圈,这很好。但我现在要做的是获得我绘制的圆圈的 ROI,即提取眼睛并将它们保存在新的 Mat 中。

这是我目前的结果:

...但正如我上面所说,只需将眼睛周围的圆圈提取到一个新的 Mat 中,每只眼睛一个。

这是我的代码:

cv::Mat plotImage;

plotImage = cv::imread("C:/temp/face.jpg", cv::IMREAD_COLOR);

cv::Point leftEye(person.GetLeftEyePoint().X, person.GetLeftEyePoint().Y);
cv::Point rightEye(person.GetRightEyePoint().X, person.GetRightEyePoint().Y);

cv::circle(plotImage, leftEye, 15, cv::Scalar(255, 255));
cv::circle(plotImage, rightEye, 15, cv::Scalar(255, 255));

cv::imwrite("C:\\temp\\plotImg.jpg", plotImage);

我找到了以下链接,但我似乎无法理解它们/将它们应用于我正在尝试做的事情: http://answers.opencv.org/question/18784/crop-image-using-hough-circle/

Selecting a Region OpenCV

Define image ROI with OpenCV in C

感谢任何帮助/指导!谢谢!

【问题讨论】:

  • 积分是怎么获得的?
  • 我正在使用分析/查找中心眼点的 SDK。我创建了自己的 Person 类来获取/设置这些值。

标签: c++ opencv mat roi


【解决方案1】:

为简单起见,让我们将其限制为一只眼睛:

// (badly handpicked coords):
Point cen(157,215);
int radius = 15;

//get the Rect containing the circle:
Rect r(cen.x-radius, cen.y-radius, radius*2,radius*2);

// obtain the image ROI:
Mat roi(plotImage, r);

// 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 & mask:
Mat eye_cropped = roi & mask;

【讨论】:

  • 非常聪明!太感谢了。 :)
  • 不确定,如果你真的想要圆形面具。否则,'roi' 已经是答案了。
  • 所以我使用了eye_cropped(结合了roi和mask)图像并进行了分析,看看眼睛是否是红色的(所以我只想分析圆圈本身)。这没关系,因为圆(矩形)的外部是黑色的。但是,现在我将 eye_cropped 图像合并回主图像,这是一个问题,因为周围的黑色矩形。我将如何去除外面的黑色以便我可以将眼睛(我已经改变了眼睛的颜色)重新合并到主图像上? roi.copyTo(plotImage(cv::Rect(person.GetLeftEyePoint().X, person.GetLeftEyePoint().Y, roi.cols, roi.rows)));
  • ...对不起,那是:croppedEye.copyTo(plotImage(cv::Rect(person.GetLeftEyePoint().X, person.GetLeftEyePoint().Y, croppedEye.cols, croppedEye.rows)));
  • 保留 roi 图像(不带遮罩),画进去,合并回原始图像?换句话说,保留任何操作的副本,您无法撤消。 ?
猜你喜欢
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 2018-05-30
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多