| 397 | // (iv) if frontal have an intereye dist at least .25 * eye_inner_rect width |
| 398 | |
| 399 | static void SelectEyes( |
| 400 | int& ileft_best, // out: index into leyes, -1 if none |
| 401 | int& iright_best, // out: index into reyes, -1 if none |
| 402 | EYAW eyaw, // in |
| 403 | const vec_Rect& leyes, // in: left eyes found by detectMultiScale |
| 404 | const vec_Rect& reyes, // in: right eyes found by detectMultiScale |
| 405 | const Rect& eye_inner_rect) // in: center of the eye must be in this region |
| 406 | { |
| 407 | ileft_best = iright_best = -1; // assume will return no eyes |
| 408 | int min_intereye = eyaw == EYAW00? cvRound(.25 * eye_inner_rect.width): 0; |
| 409 | int maxwidth = 0; // combined width of both eye boxes |
| 410 | int ileft, iright; |
| 411 | Rect left, right; |
| 412 | |
| 413 | // this part of the code will either select both eyes or no eyes |
| 414 | |
| 415 | for (ileft = 0; ileft < NSIZE(leyes); ileft++) |
| 416 | { |
| 417 | left = leyes[ileft]; |
| 418 | if (InRect(left, eye_inner_rect)) |
| 419 | { |
| 420 | for (iright = 0; iright < NSIZE(reyes); iright++) |
| 421 | { |
| 422 | right = reyes[iright]; |
| 423 | const bool c0 = InRect(right, eye_inner_rect); |
| 424 | const bool c1 = IsEyeHorizOk(left, right); |
| 425 | const bool c2 = right.x - left.x >= min_intereye; |
| 426 | const bool c3 = VerticalOverlap(left, right); |
| 427 | if (c0 && c1 && c2 && c3) |
| 428 | { |
| 429 | int total_width = left.width + right.width; |
| 430 | if (total_width > maxwidth) |
| 431 | { |
| 432 | maxwidth = total_width; |
| 433 | ileft_best = ileft; |
| 434 | iright_best = iright; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | if (ileft_best == -1 && iright_best == -1) |
| 441 | { |
| 442 | // The above loops failed to find a left and right eye in correct |
| 443 | // relationship to each other. So simply select largest left eye and |
| 444 | // largest right eye (but make sure that they are in the eye_inner_rect). |
| 445 | |
| 446 | int max_left_width = 0; |
| 447 | for (ileft = 0; ileft < NSIZE(leyes); ileft++) |
| 448 | { |
| 449 | left = leyes[ileft]; |
| 450 | if (InRect(left, eye_inner_rect)) |
| 451 | { |
| 452 | if (left.width > max_left_width) |
| 453 | { |
| 454 | max_left_width = left.width; |
| 455 | ileft_best = ileft; |
| 456 | } |
no test coverage detected