OpenCV和PHP的人脸识别技术
OpenCV安装之前必须依赖的包:(请先安装好)pkgconfiglibpngzliblibjpeglibtiffpython[OpenCV安装] www.opencv.org.tar xvzf OpenCV-1.0.0.tar.gzcd opencv-1.0.0./configuremakemake installmake check (检查是否安装全部正确)[facedetect] http://www.xarg.org/download/facedetect-1.0.0.tar.gztar xzvf facedetect-1.0.0.tar.gzcd facedetect-1.0.0/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake testmake install[ImageMagick] http://www.imagemagick.org/tar jxvf ImageMagick-6.5.0-0.tar.bz2cd ImageMagick-6.5.0-0./configuremakemake install[imagick] http://pecl.php.net/imagicktar zxvf imagick-2.3.0b1.tgzimagick-2.3.0b1/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake testmake install[配置]ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/看看有没有 facedetect.so 和 imagick.sovi /usr/local/php/lib/php.ini在[PHP]模块下增加:extension = facedetect.soextension = imagick.so重启apache[测试代码]从openCV源代码/data/haarcascades/里头取出所有xml文件放在php的执行目录下//------------------// 监测有几个人脸//------------------//检查有多少个脸型var_dump(face_count('party.jpeg', haarcascade_frontalface_alt.xml'));//返回脸型在图片中的位置参数,多个则返回数组$arr = face_detect('party.jpeg', haarcascade_frontalface_alt2.xml');print_r($arr);//------------------// 人脸扭曲//------------------<?phpif($_FILES){$img = $_FILES['pic']['tmp_name'];$arr = face_detect($img, 'haarcascade_frontalface_alt2.xml');//$arr1 = face_detect($img, 'haarcascade_frontalface_alt_tree.xml');if(is_array($arr1)) $all =array_merge($arr,$arr1);else $all = $arr;$im = new Imagick($img);//$draw =new ImagickDraw();//$borderColor = new ImagickPixel('red');//$draw->setFillAlpha(0.0);//$draw->setStrokeColor ($borderColor);//$draw->setStrokeWidth (1);if(is_array($all)){foreach ($all as $v){ $im_cl = $im->clone(); $im_cl->cropImage($v['w'],$v['h'],$v['x'],$v['y']); $im_cl->swirlImage(60); $im->compositeImage( $im_cl, Imagick::COMPOSITE_OVER , $v['x'], $v['y'] ); //$draw->rectangle($v['x'],$v['y'],$v['x']+$v['w'],$v['y']+$v['h']); //$im->drawimage($draw); }}header( "Content-Type: image/png" );echo $im;}else{?><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><form method="POST" enctype="multipart/form-data">人脸识别试验:只支持jpg,png<br>上传一张图片 <input type="file" name="pic"><input type="submit" value="upload"></form><?}?>//------------------// 人脸识别//------------------<?phpheader("Content-Type:text/html; charset:utf-8");if(empty($_POST)) {?><html><head><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"><title>人脸识别</title></head><body><h2 id="人脸识别">人脸识别</h2>PS: 请上传一张带有人脸的图片<br /><form name="form" id="form" method="POST" enctype="multipart/form-data" action="">上传图片:<input type="file" name="pic" size="20″"><input type="submit" name="submit" value="上传"></form></body></html><?php} else {$img = $_FILES['pic']['tmp_name'];$arr = face_detect($img, 'haarcascade_frontalface_alt2.xml');if(is_array($arr1)) {$all = array_merge($arr,$arr1);} else {$all = $arr;}$allowtype = 1;switch($_FILES['pic']['type']){case 'image/pjpeg': $fix_pic.= ".jpg"; break;case 'image/jpeg': $fix_pic.= ".jpg"; break;case 'image/x-png': $fix_pic.= ".png"; break;case 'image/png': $fix_pic.= ".png"; break;default: $allowtype = 0; break;}if($allowtype == 0) {echo "文件格式错误:只运行jpg或png图片";exit;}$tmp_name = time();$src_pic = "./".$tmp_name.$fix_pic;move_uploaded_file($_FILES['pic']['tmp_name'], $src_pic);$pic_src = $pic_dst = array();if(is_array($all)){foreach ($all as $k => $v){$tmp_name_new = $tmp_name."_".$k;$x = $v['x'];$y = $v['y'];$w = $v['w'];$h = $v['h'];$dst_pic = "./".$tmp_name_new.$fix_pic;// echo $src_pic."<br>";// echo $dst_pic."<br>";$cmd = "/usr/local/bin/convert -crop ".$w."x".$h."+".$x."+".$y." ".$src_pic." ".$dst_pic;// echo $cmd."<br>";echo `$cmd`;$pic_src[] = "./".$tmp_name.$fix_pic;$pic_dst[] = "./".$tmp_name_new.$fix_pic;}}foreach($pic_src as $key => $value) {echo "<img src='".$value."' alt="OpenCV跟PHP的人脸识别技术" > => <img src='".$pic_dst[$key]."' alt="OpenCV跟PHP的人脸识别技术" ><br>";}}?>
?
?
目前,还为测试,等应用后,再公布实验结果~~
?
?

phpssionscanStorestrings、numbers、arrays、andobjects.1.strings:textdatalikeusernames.2.numbers:integersorfloatsforcounters.3.arrays:listslikeshoppingcarts.4.objects:complextructuresthataresialized。

tostartaphpsession、outsession_start()atthescript'sbeginning.1)placeitbe foreanyouttosetthesscookie.2)usesionsionsionsionserdatalikelogintatussorshoppingcarts.3)再生セッションインドストップレベントフィックスアタック

セッション再生とは、新しいセッションIDを生成し、セッション固定攻撃の場合にユーザーが機密操作を実行するときに古いIDを無効にすることを指します。実装の手順には次のものが含まれます。1。感度操作を検出、2。新しいセッションIDを生成する、3。古いセッションIDを破壊し、4。ユーザー側のセッション情報を更新します。

PHPセッションは、アプリケーションのパフォーマンスに大きな影響を与えます。最適化方法には以下が含まれます。1。データベースを使用してセッションデータを保存して応答速度を向上させます。 2。セッションデータの使用を削減し、必要な情報のみを保存します。 3.非ブロッキングセッションプロセッサを使用して、同時実行機能を改善します。 4.セッションの有効期限を調整して、ユーザーエクスペリエンスとサーバーの負担のバランスを取ります。 5.永続的なセッションを使用して、データの読み取り時間と書き込み時間を減らします。

phpsesionsareserver-side、whilecookiesareclient-side.1)Sessionsionsionsoredataontheserver、aremoresecure.2)cookiesstoredataontheclient、cookiestoresecure、andlimitedinsizeisize.sesionsionsionivationivationivationivationivationivationivationivate

phpidentifiesauser'ssessionsingsinssessionCookiesIds.1)whensession_start()iscalled、phpgeneratesauniquesidstoredsored incoookienadphpsessidontheuser'sbrowser.2)thisidallowsphptortorieSessiondatadata fromthata

PHPセッションのセキュリティは、次の測定を通じて達成できます。1。session_regenerate_id()を使用して、ユーザーがログインまたは重要な操作である場合にセッションIDを再生します。 2. HTTPSプロトコルを介して送信セッションIDを暗号化します。 3。Session_Save_Path()を使用して、セッションデータを保存し、権限を正しく設定するためのSecure Directoryを指定します。

phpsessionFilesToredInthededirectoryspecifiedBysession.save_path、通常/tmponunix-likesystemsorc:\ windows \ temponwindows.tocustomizethis:1)uesession_save_path()tosetaCustomdirectory、ensuringit'swritadistradistradistradistradistra


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ホットトピック










没有,没在windows下测试。