Face detection in PHP

♀尐吖头ヾ 提交于 2019-11-30 00:32:55

It would probably be easier/safer to do this with OpenCV, which is written in lower-level code. PHP is interpreted, so it's likely going to be hella slow when doing the job.

Hope this helps!

You need to turn off error reporting

<?php

ini_set( 'display_errors', 1 );
error_reporting( E_ALL ^ E_NOTICE );

require_once('face_detector.php');

$detector = new Face_Detector('detection.dat');
$detector->face_detect('img/8.jpg');
$detector->toJpeg();

?>

Try removing the +1 from these lines:

 $ii_w = $image_width+1;
 $ii_h = $image_height+1;

This code is trying to check the colors from positions 1 to 320 instead of 0 to 319 in the 320 pixel image.

This is an old topic but still this fix is better than any I saw so far so, it might help someone

// Turn off error reporting...
$ctl = error_reporting();
error_reporting(0);

$detector = new Face_Detector('detection.dat');
$detector->face_detect('img/8.jpg');
$detector->toJpeg();

// Turn on reporting...if you wish
error_reporting($ctl);
Jakob Sternberg

Quick fix: in the compute_ii function

Replace:

$rgb = ImageColorAt($canvas, $j, $i);

With:

$rgb = ImageColorAt($canvas, $j-1, $i-1);

The project has been upgraded on github repository by following this link Face detection

The problem was on the loop, this code works fine :

for ($i=1; $i<$ii_h-1; $i++) {
        $ii[$i*$ii_w] = 0;
        $ii2[$i*$ii_w] = 0;
        $rowsum = 0;
        $rowsum2 = 0;
        for ($j=1; $j<$ii_w-1; $j++) {
            $rgb = ImageColorAt($canvas, $j, $i);
            $red = ($rgb >> 16) & 0xFF;
            $green = ($rgb >> 8) & 0xFF;
            $blue = $rgb & 0xFF;
            $grey = (0.2989*$red + 0.587*$green + 0.114*$blue)>>0;  // this is what matlab uses
            $rowsum += $grey;
            $rowsum2 += $grey*$grey;

            $ii_above = ($i-1)*$ii_w + $j;
            $ii_this = $i*$ii_w + $j;

            $ii[$ii_this] = $ii[$ii_above] + $rowsum;
            $ii2[$ii_this] = $ii2[$ii_above] + $rowsum2;
        }
    }

Good luck

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!