Skip to content

Instantly share code, notes, and snippets.

@Gaia-Murata
Last active December 13, 2015 21:08
Show Gist options
  • Save Gaia-Murata/4975157 to your computer and use it in GitHub Desktop.
Save Gaia-Murata/4975157 to your computer and use it in GitHub Desktop.
Apple信者ならFlash使わずPHP拡張face_detectで顔認証するよね! 顔認識
<?php
function LoadJpeg($imgname)
{
/* オープンします */
$im = @imagecreatefromjpeg($imgname);
/* 失敗したかどうかを調べます */
if(!$im)
{
/* エラーメッセージを出力します */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/jpeg');
$imgfile = 'lena.jpg';
$img = LoadJpeg($imgfile);
//顔認識を行う
$faces = face_detect($imgfile,'haarcascade_frontalface_default.xml');
$red = imagecolorallocate($img,255, 0, 0);
if(count($faces) > 0) {
foreach ($faces as $face) {
imagerectangle($img, $face['x'] ,$face['y'] , $face['x']+$face['w'], $face['y']+$face['h'], $red);
}
}
imagejpeg($img);
imagedestroy($baseImg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment