Last active
December 13, 2015 21:08
-
-
Save Gaia-Murata/4975157 to your computer and use it in GitHub Desktop.
Apple信者ならFlash使わずPHP拡張face_detectで顔認証するよね!
顔認識
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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