Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to show overlay image over detected face in openCv c++?

I am working on face detection using openCv in iOS platform. I am using openCv in c++. It detects face nicely and I am able to draw a rectangle around this face. But I need to show a overlay image instead of rectangle. Here is my code.

 - (void)processImage:(Mat&)image;
 {

     cv::cvtColor(image, img, CV_BGR2GRAY);
     equalizeHist(img, img);
     NSString* cascadePath = [[NSBundle mainBundle]
                              pathForResource:@"haarcascade_frontalface_alt2"
                              ofType:@"xml"];

     CascadeClassifier face_cascade;

     face_cascade.load([cascadePath UTF8String]);

     std::vector<cv::Rect> faces;
     face_cascade.detectMultiScale(img, faces, 1.1,
                                   2, haarOptions, cv::Size(30, 30));

     for(unsigned int i = 0; i < faces.size(); i++) {

         cv::Point p1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
         cv::Point p2(faces[i].x , faces[i].y);
         cv::Scalar magenta = cv::Scalar(255, 10, 255);
         cv::Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
         //const std::string text = Eye;
          cv::putText(image, Face,p2 ,FONT_HERSHEY_SIMPLEX, 1, Scalar(0,200,200), 2);
          cv::rectangle(image, p1, p2, magenta,1,8,0);

     }
}

Here is my output..

image description

Now I want replace this rectangle with an overlay image. Is it possible? If so then please help me. Thanks in advanced.

click to hide/show revision 2
retagged

updated 2018-03-25 04:32:18 -0600

berak gravatar image

How to show overlay image over detected face in openCv c++?

I am working on face detection using openCv in iOS platform. I am using openCv in c++. It detects face nicely and I am able to draw a rectangle around this face. But I need to show a overlay image instead of rectangle. Here is my code.

 - (void)processImage:(Mat&)image;
 {

     cv::cvtColor(image, img, CV_BGR2GRAY);
     equalizeHist(img, img);
     NSString* cascadePath = [[NSBundle mainBundle]
                              pathForResource:@"haarcascade_frontalface_alt2"
                              ofType:@"xml"];

     CascadeClassifier face_cascade;

     face_cascade.load([cascadePath UTF8String]);

     std::vector<cv::Rect> faces;
     face_cascade.detectMultiScale(img, faces, 1.1,
                                   2, haarOptions, cv::Size(30, 30));

     for(unsigned int i = 0; i < faces.size(); i++) {

         cv::Point p1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
         cv::Point p2(faces[i].x , faces[i].y);
         cv::Scalar magenta = cv::Scalar(255, 10, 255);
         cv::Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
         //const std::string text = Eye;
          cv::putText(image, Face,p2 ,FONT_HERSHEY_SIMPLEX, 1, Scalar(0,200,200), 2);
          cv::rectangle(image, p1, p2, magenta,1,8,0);

     }
}

Here is my output..

image description

Now I want replace this rectangle with an overlay image. Is it possible? If so then please help me. Thanks in advanced.