Question

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?

Was it helpful?

Solution 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 ?

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top