Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

time to start preliminary answers, i guess,..

1) yes, try a CascadeClassifier. if you can find out, that you can crop your images to the significant face part, you've already won something.

2) optional align to eyes. you can use another CascadeClassifier to find them, or some landmarks, like from flandmark or dlib. then, it's basically this:

    double eyeXdis = eye_r.x - eye_l.x;
    double eyeYdis = eye_r.y - eye_l.y;
    double angle   = atan(eyeYdis/eyeXdis);
    double degree  = angle*180/CV_PI;
    double desired_eye_distance = 44.0;
    double scale   = desired_eye_distance / eyeXdis; 

    Mat res;
    Point2f center(test.cols/2, test.rows/2);
    Mat rot = getRotationMatrix2D(center, degree, scale);
    warpAffine(test, res, rot, Size(), INTER_CUBIC, BORDER_CONSTANT, Scalar(127));
   // probably crop this again from center

3) now it's time to compare the images. ofc. you can save them to disk with imwrite() and use phash on that, but while you're in opencv, might as well try some other things:

  • the most simple comparison would be a straight double dist = norm(a,b); and compare to some threshold
  • instead of using the plain image pixels, you could advance to 'features' gotten from that, like hog, lbph, or the mentioned surf or orb descriptors
  • this is called 'face verification', an active research topic ;)

time to start preliminary answers, i guess,..

1) yes, try a CascadeClassifier. if you can find out, that you can crop your images to the significant face part, you've already won something.

2) 3) optional align to eyes. you can use another CascadeClassifier to find them, or some landmarks, like from flandmark or dlib. then, it's basically this:

    double eyeXdis = eye_r.x - eye_l.x;
    double eyeYdis = eye_r.y - eye_l.y;
    double angle   = atan(eyeYdis/eyeXdis);
    double degree  = angle*180/CV_PI;
    double desired_eye_distance = 44.0;
    double scale   = desired_eye_distance / eyeXdis; 

    Mat res;
    Point2f center(test.cols/2, test.rows/2);
    Mat rot = getRotationMatrix2D(center, degree, scale);
    warpAffine(test, res, rot, Size(), INTER_CUBIC, BORDER_CONSTANT, Scalar(127));
   // probably crop this again from center

3) 4) now it's time to compare the images. ofc. you can save them to disk with imwrite() and use phash on that, but while you're in opencv, might as well try some other things:

  • the most simple comparison would be a straight double dist = norm(a,b); and compare to some threshold
  • instead of using the plain image pixels, you could advance to 'features' gotten from that, like hog, lbph, or the mentioned surf or orb descriptors
  • this is called 'face verification', an active research topic ;)

time to start preliminary answers, i guess,..

1) yes, try a CascadeClassifier. if you can find out, that you can crop your images to the significant face part, you've already won something.

2) 3) optional align to eyes. you can use another CascadeClassifier to find them, or some landmarks, like from flandmark or dlib. then, it's basically this:

    double eyeXdis = eye_r.x - eye_l.x;
    double eyeYdis = eye_r.y - eye_l.y;
    double angle   = atan(eyeYdis/eyeXdis);
    double degree  = angle*180/CV_PI;
    double desired_eye_distance = 44.0;
    double scale   = desired_eye_distance / eyeXdis; 

    Mat res;
    Point2f center(test.cols/2, test.rows/2);
    Mat rot = getRotationMatrix2D(center, degree, scale);
    warpAffine(test, res, rot, Size(), INTER_CUBIC, BORDER_CONSTANT, Scalar(127));
   // probably crop this again from center

4) now it's time to compare the images. ofc. you can save them to disk with imwrite() and use phash on that, but while you're in opencv, might as well try some other things:

  • the most simple comparison would be a straight double dist = norm(a,b); and compare to some threshold
  • if you got a good count of 'same' , 'not-same' pairs somehow, you could train that distance, also could use machine-learning, like an svm trained on distances
  • instead of using the plain image pixels, you could advance to 'features' gotten from that, like hog, lbph, or the mentioned surf or orb descriptors
  • this is called 'face verification', an active research topic ;)

time to start preliminary answers, i guess,..

1) yes, try a CascadeClassifier. if you can find out, that you can crop your images to the significant face part, you've already won something.

2) 3) optional align to eyes. you can use another CascadeClassifier to find them, or some landmarks, like from flandmark or dlib. then, it's basically this:

    double eyeXdis = eye_r.x - eye_l.x;
    double eyeYdis = eye_r.y - eye_l.y;
    double angle   = atan(eyeYdis/eyeXdis);
    double degree  = angle*180/CV_PI;
    double desired_eye_distance = 44.0;
    double scale   = desired_eye_distance / eyeXdis; 

    Mat res;
    Point2f center(test.cols/2, test.rows/2);
    Mat rot = getRotationMatrix2D(center, degree, scale);
    warpAffine(test, res, rot, Size(), INTER_CUBIC, BORDER_CONSTANT, Scalar(127));
   // probably crop this again from center

4) now it's time to compare the images. ofc. you can save them to disk with imwrite() and use phash on that, but while you're in opencv, might as well try some other things:

  • the most simple comparison would be a straight double dist = norm(a,b); and compare to some threshold
  • if you got a good count of 'same' , 'not-same' pairs somehow, you could train that distance, also could use machine-learning, like an svm trained on distances
  • instead of using the plain image pixels, you could advance to 'features' gotten from that, like dct(similar to phash), hog, lbph, or the mentioned surf or orb descriptors
  • this is called 'face verification', an active research topic ;)