0

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?

Simon
  • 509
  • 7
  • 25

2 Answers2

3

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.

Community
  • 1
  • 1
baci
  • 2,528
  • 15
  • 28
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 ?

Marcassin
  • 1,386
  • 1
  • 11
  • 21
  • The conversion succeeded but I get the following error: OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array') in compare – Simon Nov 29 '13 at 07:57
  • In the documentation of compare method : `src1 : first input array or a scalar, when it is an array, it must have a single channel.` roi from ImgGray is a single-channel Matrix, be sure OriginalImg is composed by only 1 channel too. By The Way C.Canberk Bac is right about features recognition isn't that simple that "compare" 2 ROI. – Marcassin Nov 29 '13 at 11:23