Skip to content

Commit

Permalink
eye zoom corrected slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrence Curran committed Jun 11, 2012
1 parent 6914167 commit f1c07dc
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions src/Main.cpp
Expand Up @@ -123,7 +123,7 @@ int main(int argc, char** argv) {
void processImage(char * imageFile) {

if (opt_debug) {
printf("Loading Image:%s\n", imageFile);
printf("\n\nLoading Image:%s\n", imageFile);
}

IplImage* img = cvLoadImage(imageFile, 1);
Expand Down Expand Up @@ -215,6 +215,14 @@ void processImage(char * imageFile) {
faceRect->width = faceRect->width + expandX;
faceRect->height = faceRect->height + expandY;

if (opt_debug) {
printf("face found\n");
printf("\tx: %d\n", faceRect->x);
printf("\ty: %d\n", faceRect->y);
printf("\twidth: %d\n", faceRect->width);
printf("\theight: %d\n", faceRect->height);
}

IplImage *faceBlock = CvUtils::Sub_Image(
small_img,
cvRect(faceRect->x, /* x = start from leftmost */
Expand All @@ -229,18 +237,25 @@ void processImage(char * imageFile) {

CvPoint leftEye = cvPoint(0, 0);
CvPoint rightEye = cvPoint(0, 0);
CvPoint leftEyeAbsolute = cvPoint(0, 0);
CvPoint rightEyeAbsolute = cvPoint(0, 0);

// look for eyes in the photo
//cvClearMemStorage( storage );
eyeDetector->find(faceBlock, &leftEye, &rightEye);
leftEye.x = (faceRect->x + leftEye.x);
leftEye.y = (faceRect->y + leftEye.y);
rightEye.x = (faceRect->x + rightEye.x);
rightEye.y = (faceRect->y + rightEye.y);
leftEyeAbsolute.x = (faceRect->x + leftEye.x);
leftEyeAbsolute.y = (faceRect->y + leftEye.y);
rightEyeAbsolute.x = (faceRect->x + rightEye.x);
rightEyeAbsolute.y = (faceRect->y + rightEye.y);

if (opt_debug) {
printf("\tleft eye x: %d, y: %d\n", leftEye.x, leftEye.y);
printf("\tleft eye x: %d, y: %d\n", rightEye.x, rightEye.y);
}

// draw crosshairs where we think the eyes are
CvUtils::drawCrosshair(&leftEye, imgMarkup, 255, 0, 0);
CvUtils::drawCrosshair(&rightEye, imgMarkup, 0, 0, 255);
CvUtils::drawCrosshair(&leftEyeAbsolute, imgMarkup, 255, 0, 0);
CvUtils::drawCrosshair(&rightEyeAbsolute, imgMarkup, 0, 0, 255);


// write the face as it was found in the image
Expand Down Expand Up @@ -318,6 +333,7 @@ void processImage(char * imageFile) {
double zoomScale = 1;
// scale the train rectangle to the size it will need to be to align the eyes.
if (leftEye.x > 0 && rightEye.x > 0) {

// see if we need to resize the height/width of the face block
int targetLeftEyeX = int(canonicalLeftEye[0] * targetScale);
int targetRightEyeX = int(canonicalRightEye[0] * targetScale);
Expand Down Expand Up @@ -382,6 +398,25 @@ void processImage(char * imageFile) {
//faceimg = cvCloneImage(img);
cvResize(imgOperation, faceTrain, CV_INTER_LINEAR);

if (opt_show_ui) {
cvNamedWindow("scaled", 1);
cvShowImage("scaled", faceTrain);
cvResizeWindow("scaled", faceTrain->width, faceTrain->height);
}

// write the rotated image
if (opt_output_path) {
char *destImageUri = new char[strlen(opt_output_path) + strlen("scaled_") + strlen(imageFileName) + 1];
sprintf(destImageUri, "%scaled_%s", opt_output_path, imageFileName);
if (opt_debug) {
printf("Saving scaled image to %s\n", destImageUri);
}
cvSaveImage(destImageUri, faceTrain);
delete[] destImageUri;
}

cvReleaseImage(&faceTrain);

CvPoint leftEyeTrained = cvPoint(
int(leftEye.x / targetScale / zoomScale),
int(leftEye.y / targetScale / zoomScale)
Expand Down Expand Up @@ -512,7 +547,8 @@ int loadOptions(int argc, char *argv[]) {
opt->addUsage(" -D --draw-features Draw the facial feature regions");
opt->addUsage(" -u --show-ui Show UI");
opt->addUsage(" -d --debug Debug");
opt->addUsage(" -R --rotate Rotate and scale face based on eye detection");
opt->addUsage(" -R --rotate Rotate face based on eye detection");
opt->addUsage(" -z --zoom Zoom face based on eye detection");

opt->addUsage("");
opt->addUsage("Options: ");
Expand All @@ -529,6 +565,7 @@ int loadOptions(int argc, char *argv[]) {
opt->setFlag("show-ui", 'u');
opt->setFlag("debug", 'd');
opt->setFlag("rotate", 'R');
opt->setFlag("zoom", 'z');

opt->setOption("cascade", 'c');
opt->setOption("left-eye-cascade", 'l');
Expand Down Expand Up @@ -570,6 +607,10 @@ int loadOptions(int argc, char *argv[]) {
opt_rotate = true;
}

if (opt->getFlag('z') || opt->getFlag("zoom")) {
opt_zoom = true;
}

if (opt->getValue('c') != NULL || opt->getValue("cascade") != NULL) {
opt_cascade_face = opt->getValue('c');
}
Expand Down

0 comments on commit f1c07dc

Please sign in to comment.