You are here

protected function Face_Detector::do_detect_greedy_big_to_small in Image Focus Crop 7

Same name and namespace in other branches
  1. 6 php-facedetection/FaceDetector.php \Face_Detector::do_detect_greedy_big_to_small()
1 call to Face_Detector::do_detect_greedy_big_to_small()
Face_Detector::face_detect in php-facedetection/FaceDetector.php

File

php-facedetection/FaceDetector.php, line 142

Class

Face_Detector

Code

protected function do_detect_greedy_big_to_small($ii, $ii2, $width, $height) {
  $s_w = $width / 20.0;
  $s_h = $height / 20.0;
  $start_scale = $s_h < $s_w ? $s_h : $s_w;
  $scale_update = 1 / 1.2;
  for ($scale = $start_scale; $scale > 1; $scale *= $scale_update) {
    $w = 20 * $scale >> 0;
    $endx = $width - $w - 1;
    $endy = $height - $w - 1;
    $step = max($scale, 2) >> 0;
    $inv_area = 1 / ($w * $w);
    for ($y = 0; $y < $endy; $y += $step) {
      for ($x = 0; $x < $endx; $x += $step) {
        $passed = $this
          ->detect_on_sub_image($x, $y, $scale, $ii, $ii2, $w, $width + 1, $inv_area);
        if ($passed) {
          return array(
            'x' => $x,
            'y' => $y,
            'w' => $w,
          );
        }
      }

      // end x
    }

    // end y
  }

  // end scale
  return null;
}