Search code examples
opencvrectmat

Opencv compare Rects


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?


Solution

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