I get a vector of Rect by calling DetectMultiScale:

face_cascade.detectMultiScale(ImgGray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE);

But Compare requires Mat:

compare(OriginalImg,roi,dist,CMP_EQ);

How do I convert Rect to Mat to make the comparison or is there a way to compare Rects?

有帮助吗?

解决方案 2

If you want to compare 2 images, your compare function take 2 cv::Mat as firsts inputs. To take the roi from your ImgGray you have to extract a new Mat from the ROI given by detectMultiScale

Mat ImgGray;
vector<Rect> faces;
face_cascade.detectMultiScale(ImgGray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE);
Rect roiRect = faces[0];
Mat roi = ImgGray (roiRect);
compare(OriginalImg,roi,dist,CMP_EQ);

OriginalImg, dist and roi have the same size and type. Does that resolve your problem ?

其他提示

0 - It is compare, not detect. It performs per element comparison

1- You can not convert Rect to Mat, since one defines a 4 point geometrical shape whereas other defines a 3D matrix.

2- You can crop your Mat with a Rect, and use that new Mat inside compare

3- Face recognition is not that simple. Please check out this tutorial.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top