我在cv :: Mat中有一个图像作为面部,我在cv :: Rect对象中需要整个图像,但我找不到它的完成方式,或者可能的话,从目录中的图像创建Rect
you don't convert a cv::Mat to a cv::Rect.
you want the part of the image inside that Rect ?
Mat roi = Mat(img,rect);
will give you the cropped region
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);
Although, as @berak says, you can't convert a cv::Mat to a cv::Rect, I am guessing you want something like this (untested).
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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.