簡體   English   中英

如何將cv :: Mat轉換為cv :: Rect

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM