Ask Your Question
0

Face & Facial Features cropping using openCV in IOS

asked 2014-01-21 23:56:46 -0600

Krishna gravatar image

updated 2014-01-22 00:43:47 -0600

Hello ,

I am developing the project where I am detecting Face and facial features and crop the features and Overlap on to the object.

Heretofore i have done detecting the Face,eyes and Mouth , My next step is to crop the face,eyes and Mouth.

Problem: While cropping the Face, I am assigning the region (Rect ) from where i get using haarcascade. I will then draw the rectangle on to the real image, till here everything goes fine . but during the cropping when i assign same region , I won't get the exact Face region .

Here is the code for detecting and getting sub image.

 for (int i = 0; i < faces.size(); i++)
    {
        cv::Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
        cv::Point pt2(faces[i].x, faces[i].y);
        cv::rectangle(image, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8 ,0);
        cv::Rect myROI(faces[i].x, faces[i].y, faces[i].width,  faces[i].height );
        Mat subImage(grayscaleFrame, myROI);

       if(!subImage.empty()){
       UIImage * image1=  [self UIImageFromCVMat:subImage];

  }

Here you can see the image : http://i.stack.imgur.com/YkaQK.png

Please suggest me where i am going wrong in the code .

Thanks

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-01-23 04:14:11 -0600

updated 2014-01-23 04:14:48 -0600

Actually, can you specify which format your faces object has? Normally when using it with the built-in face detection, the Viola&Jones detector, you will receive a vector<cv::rect>, so I am really wondering why you would go trough the trouble of creating a new rectangle...

If this is correct, the subimage can be get by doing the following

vector<cv::Rect> faces;
// Perform detection and output it in faces

for (int i = 0; i < faces.size(); i++)
{
    // Make sure to make a clone else your pointer structure (basics behind Mat can ruin your output!
    Mat subImage = grayscaleFrame(faces[i]).clone();

    if(!subImage.empty()){
        UIImage * image1=  [self UIImageFromCVMat:subImage];
    }
}
edit flag offensive delete link more
0

answered 2014-01-22 21:32:37 -0600

MRDaniel gravatar image

There is an overload for cv::Rect.

cv::Rect myROI(pt1, pt2);

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-01-21 23:56:46 -0600

Seen: 1,871 times

Last updated: Jan 23 '14