Ask Your Question
1

How to draw rectangle using left eye, right eye, nose, mouth left and right points

asked 2015-06-16 01:53:08 -0600

Mohanraj gravatar image

I have detected the facial feature points using flandmark detector and i rotated face image and i have found the rotated facial feature also. how to normalize the face regions.

edit retag flag offensive close merge delete

Comments

1) see http://docs.opencv.org/ref/master/d3/...

2) did you mean intensity/lighting normalization ? or shape/geometry normalization ?

berak gravatar imageberak ( 2015-06-16 02:08:09 -0600 )edit

i want to normalize the face region using left eye, right eye, nose, mouth left and right points. but haar detector gives more regions for face, so i have detected the facial feature points based on that i want to normalize the face

Mohanraj gravatar imageMohanraj ( 2015-06-16 03:54:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-06-16 04:04:39 -0600

updated 2015-06-16 08:11:18 -0600

For example, you can check this paper:

"An experimental comparison of gender classification methods" http://www.inf.unideb.hu/~sajolevente/papers2/gender/2008.%20An%20experimental%20comparison%20of%20gender%20classification%20methods.pdf

In table 1 you can see a face normalization algorithm.

image description

This code need to be checked:

class RegionNormalizer{
public:
RegionNormalizer(){};

virtual ~RegionNormalizer() {
}
;

virtual cv::Mat process(const cv::Mat& aligned_image, const cv::Rect& region, const std::vector<cv::Point2d> & landmarks) = 0;

inline double euclidean_distance(const cv::Point &p1, const cv::Point &p2){
    double dx = p1.x - p2.x;
    double dy = p1.y - p2.y;
    return sqrt(dx * dx + dy * dy);
}

};


class GenericFlandmarkRegionNormalizer: public RegionNormalizer{
public:
GenericFlandmarkRegionNormalizer(const cv::Size& size, double eyes_distance_percentage, double hr);
virtual ~GenericFlandmarkRegionNormalizer();
virtual cv::Mat process(const cv::Mat& normalized_image, const cv::Rect& face, const       std::vector<cv::Point2d> & landmarks);

private:

cv::Size size_resized;
double eyes_distance_percentage;
double hr;

};


/*
example values
size(80,84) , eyes_distance_percentage = 0.75 , hr = 3.5
*/

GenericFlandmarkRegionNormalizer::GenericFlandmarkRegionNormalizer(const Size& size,  double eyes_distance_percentage, double hr){
this->size_resized = size;
this->eyes_distance_percentage = eyes_distance_percentage;
this->hr = hr; 
}


Mat GenericFlandmarkRegionNormalizer::process(const Mat& normalized_image, const Rect& face, const vector<Point2d> & landmarks){

// wt = width of the resized image
int wt = this->size_resized.width;

// ht = height of the resized image
int ht = this->size_resized.height;

// 1. Eyes are located
Point2d right_eye = landmarks[RIGHT_EYE_ALIGN];
Point2d left_eye = landmarks[LEFT_EYE_ALIGN];

//2. Image is rotated, so that eyes are vertically aligned --> image is aligned

//3. Euclidean distance between the eyes is calculated in the rotated image
int d0 = euclidean_distance(right_eye,left_eye);

//4. Ratio r is calculated by r =  d0 / dt, where dt is distance of the eyes in the resized image

//dt is distance of the eyes in the resized image
int dt = this->size_resized.width * this->eyes_distance_percentage;

double r = (d0*1.0) / dt;

//5. Width w0 and height h0 of the area around the eyes are calculated (in the source image)
int w0 = r * wt;
int h0 = r * ht;

//6. Coordinates for the corners of the face area in the rotated image are calculated
//rh = ratio of the height above and below eyes 

//xe = is x-coordinate of the point in halfway between the eyes
int xe = d0/2 + left_eye.x;

//yt = y-coordinate of the top border
int ye = left_eye.y;

//xl is x-coordinate of the left border
int xl = xe - w0/2; 
//yt is y-coordinate of the top border
//int yt = ye - h0/hr;
int yt = ye - h0/this->hr;
//xr is x-coordinate of the right border
int xr = xl + w0;
//yb is y-coordinate of the bottom border
int yb = yt + h0;

Point2d cropXY = Point2d(xl,yt);
int width = xr - xl;
int height = yb - yt;

Size cropSize = Size(width,height);

Rect cropRect(cropXY, cropSize);

if (cropRect == Rect()){
   return Mat();
}

//check valid ROI:
Rect image_rect = Rect(0,0,normalized_image.cols,normalized_image.rows);
if((cropRect & image_rect) != cropRect){

    cout<<cropRect.width <<" "<<cropRect.height <<endl;
    cout<<image_rect.width <<" "<<image_rect.height <<endl;

    cout<<"Bad ROI"<<endl;
    return Mat();
}
}
edit flag offensive delete link more

Comments

thanks for providing your code, now i got output for face normalization.

Mohanraj gravatar imageMohanraj ( 2015-06-16 08:42:42 -0600 )edit

/* example values size(80,84) , eyes_distance_percentage = 0.75 , hr = 3.5 */ How is the eyes_distance_percentage is formulated ? @albertofernandez

Mohanraj gravatar imageMohanraj ( 2015-07-14 04:49:55 -0600 )edit

You should do some test in order to adjust these values.

eyes_distance_percentage = percentage of the distance from left oyter eye to right outer eye in the resized image.

albertofernandez gravatar imagealbertofernandez ( 2015-07-14 05:21:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-16 01:53:08 -0600

Seen: 1,867 times

Last updated: Jun 16 '15