[英]How do I convert a cv::Mat to a cv::Rect
我在cv :: Mat中有一个图像作为面部,我在cv :: Rect对象中需要整个图像,但我找不到它的完成方式,或者可能的话,从目录中的图像创建Rect
您不会将cv :: Mat转换为cv :: Rect。
您想要该Rect 内的图像部分吗?
Mat roi = Mat(img,rect);
会给你裁剪的区域
cv :: Mat无法直接给您一个cv :: Rect,但您可以使用cv :: Mat的size()方法并假设cv :: Rect的起点是(0 ,0)
cv::Mat image; // load your image into the cv::Mat ... // now create the cv::Rect from the cv::Mat cv::Rect rect = cv::Rect(0, 0, image.size().width, image.size().height);
虽然,正如@berak所说,您不能将cv :: Mat转换为cv :: Rect,但我猜您想要这样的东西(未经测试)。
cv::Mat face; // you already have this with some data in it
cv::Mat image; // you already have this with some data in it
cv::Rect rect(x, y, w, h); // some place in image where you want face
// copy face into rectange within image
cv::resize(face, image(rect), cv::Size(rect.width, rect.height));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.