Face preprocessing is not working in java. [closed]

asked 2013-12-10 06:13:22 -0600

vivek0402 gravatar image

updated 2013-12-10 06:15:17 -0600

I am working on face recognition using java library of open cv. I got stuck on face pre processsing phase. here is my code.

    double desiredFaceHeight=70;
    double desiredFaceWidth=70;
    double desiredLen=(DESIRED_RIGHT_EYE_X-0.16);
    try{
    double dy= (face.getRightEye().y-face.getLeftEye().y);
    double dx= (face.getRightEye().x-face.getLeftEye().x);
    double len=Math.sqrt((dx*dx)+(dy*dy));
    double scale=desiredLen*desiredFaceWidth/len;
    // Get the transformation matrix for the desired angle & size.
    Mat rotMat=Imgproc.getRotationMatrix2D(face.getCenterOfEyes(),face.getEyesAngle(), scale);

    //Shift the center of the eyes to be the desired center.
    double ex= desiredFaceWidth*0.5f-face.getCenterOfEyes().x;
    double ey=desiredFaceHeight*DESIRED_LEFT_EYE_Y-face.getCenterOfEyes().y;
    rotMat.put(0,2,rotMat.get(0,2)[0]+ex);//view
    rotMat.put(1,2,rotMat.get(1,2)[0]+ey);//view

    Mat warped = new Mat((int)desiredFaceHeight, (int)desiredFaceWidth,CvType.CV_8U,new Scalar(128));
    //Mat warped=face.getFace();
    Imgproc.warpAffine(face.getFace(),warped, rotMat, warped.size());

but it does not gives transformed face. please describe what's wrong I am doing.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2013-12-11 06:12:08.948225

Comments

1

similar prob here - let me guess, scale & offset is right, but (almost) no rotation ?

berak gravatar imageberak ( 2013-12-10 06:29:43 -0600 )edit

I have checked rotation matrix. values are getting change.

vivek0402 gravatar imagevivek0402 ( 2013-12-10 06:39:08 -0600 )edit

Just a guess, this complete code depends on the fact that there is actually a detection of both eyes. Where do you catch the fact that one of these parameters is unknown?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-12-10 06:40:53 -0600 )edit

@StevenPuttemans I am actually accepting only those faces in which both eyes are detected.

vivek0402 gravatar imagevivek0402 ( 2013-12-10 11:02:35 -0600 )edit

Okay was a simple guess, no idea why it doesn't do what its supposed to do... not a java expert here...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-12-11 03:03:40 -0600 )edit
1

I got what the problem was. actually the center of face about which the face was rotated was calculated wrongly.

vivek0402 gravatar imagevivek0402 ( 2013-12-11 06:10:16 -0600 )edit

Ok than this can be closed and marked as solved.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-12-11 06:11:37 -0600 )edit