You are here

protected function Face_Detector::detect_on_sub_image in Image Focus Crop 6

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

File

php-facedetection/FaceDetector.php, line 165

Class

Face_Detector

Code

protected function detect_on_sub_image($x, $y, $scale, $ii, $ii2, $w, $iiw, $inv_area) {
  $mean = ($ii[($y + $w) * $iiw + $x + $w] + $ii[$y * $iiw + $x] - $ii[($y + $w) * $iiw + $x] - $ii[$y * $iiw + $x + $w]) * $inv_area;
  $vnorm = ($ii2[($y + $w) * $iiw + $x + $w] + $ii2[$y * $iiw + $x] - $ii2[($y + $w) * $iiw + $x] - $ii2[$y * $iiw + $x + $w]) * $inv_area - $mean * $mean;
  $vnorm = $vnorm > 1 ? sqrt($vnorm) : 1;
  $passed = true;
  for ($i_stage = 0; $i_stage < count($this->detection_data); $i_stage++) {
    $stage = $this->detection_data[$i_stage];
    $trees = $stage[0];
    $stage_thresh = $stage[1];
    $stage_sum = 0;
    for ($i_tree = 0; $i_tree < count($trees); $i_tree++) {
      $tree = $trees[$i_tree];
      $current_node = $tree[0];
      $tree_sum = 0;
      while ($current_node != null) {
        $vals = $current_node[0];
        $node_thresh = $vals[0];
        $leftval = $vals[1];
        $rightval = $vals[2];
        $leftidx = $vals[3];
        $rightidx = $vals[4];
        $rects = $current_node[1];
        $rect_sum = 0;
        for ($i_rect = 0; $i_rect < count($rects); $i_rect++) {
          $s = $scale;
          $rect = $rects[$i_rect];
          $rx = $rect[0] * $s + $x >> 0;
          $ry = $rect[1] * $s + $y >> 0;
          $rw = $rect[2] * $s >> 0;
          $rh = $rect[3] * $s >> 0;
          $wt = $rect[4];
          $r_sum = ($ii[($ry + $rh) * $iiw + $rx + $rw] + $ii[$ry * $iiw + $rx] - $ii[($ry + $rh) * $iiw + $rx] - $ii[$ry * $iiw + $rx + $rw]) * $wt;
          $rect_sum += $r_sum;
        }
        $rect_sum *= $inv_area;
        $current_node = null;
        if ($rect_sum >= $node_thresh * $vnorm) {
          if ($rightidx == -1) {
            $tree_sum = $rightval;
          }
          else {
            $current_node = $tree[$rightidx];
          }
        }
        else {
          if ($leftidx == -1) {
            $tree_sum = $leftval;
          }
          else {
            $current_node = $tree[$leftidx];
          }
        }
      }
      $stage_sum += $tree_sum;
    }
    if ($stage_sum < $stage_thresh) {
      return false;
    }
  }
  return true;
}