Permalink
Browse files

First Commit [Nikos M.]

  • Loading branch information...
0 parents commit f832c33ee6a8349b4e1847405274896d4f3135a1 unknown committed Feb 28, 2012
Oops, something went wrong.
Oops, something went wrong.
@@ -0,0 +1,2 @@
+REM %1 is opencv haar xml file name without xml extension
+java -jar haartophp.jar %1.xml %1 > %1.php
Binary file not shown.
@@ -0,0 +1,18 @@
+/* MISC, PREPARATORY */
+
+#feedback { padding: 4px; background: #eee; color: #55b; border: solid 1px #bbb; font-weight: bold; text-align: center; }
+
+
+/* FORM */
+
+#imgForm { border: solid 4px #ddd; background: #eee; padding: 10px; margin: 30px; width: 600px; overflow:hidden;}
+ #imgForm label { float: left; width: 200px; font-weight: bold; color: #666; clear:both; padding-bottom:10px; }
+ #imgForm input { float: left; }
+ #imgForm input[type="submit"] {clear:both; }
+ #img_upload { width: 400px; }
+ #img_name { width: 200px; }
+
+
+/* DRAG BOX */
+
+#drag_box { position: absolute; border: solid 1px #333; background: #fff; opacity: .5; alpha(opacity=50); z-index: 10; filter: alpha(opacity=50); }
@@ -0,0 +1,72 @@
+<?php
+require_once('../cascades/haarcascade_frontalface_alt.php');
+require_once('../src/haar-detector.class.php');
+
+/* -----------------
+| UPLOAD FORM - validate form and handle submission
+----------------- */
+$error='';
+if (isset($_POST['upload_form_submitted'])) {
+ if (!isset($_FILES['img_upload']) || empty($_FILES['img_upload']['name'])) {
+ $error = "Error: You didn't upload a file";
+ } else if (!isset($_POST['img_name']) || empty($_POST['img_name'])) {
+ $error = "Error: You didn't specify a file name";
+ } else {
+ $allowedExtensions = array('jpg', 'jpeg', 'gif', 'png');
+ preg_match('/\.('.implode($allowedExtensions, '|').')$/', $_FILES['img_upload']['name'], $fileExt);
+ $newPath = 'imgs/'.$_POST['img_name'].'.'.$fileExt[1];
+ /*if (file_exists($newPath)) {
+ $error = "Error: A file with that name already exists";
+ } else*/ if (!in_array(substr($fileExt[0], 1), $allowedExtensions)) {
+ $error = 'Error: Invalid file format - please upload a picture file';
+ } else if (!copy($_FILES['img_upload']['tmp_name'], $newPath)) {
+ $error = 'Error: Could not save file to server';
+ } else {
+ $_SESSION['newPath'] = $newPath;
+ $_SESSION['fileExt'] = $fileExt;
+ }
+ }
+}
+
+
+/* -----------------
+| CROP saved image
+----------------- */
+if (isset($_POST['upload_form_submitted'])) {
+
+ switch($_SESSION['fileExt'][1]) {
+ case 'jpg': case 'jpeg':
+ $source_img = imagecreatefromjpeg($_SESSION['newPath']);
+ break;
+ case 'gif':
+ $source_img = imagecreatefromgif($_SESSION['newPath']);
+ break;
+ case 'png':
+ $source_img = imagecreatefrompng($_SESSION['newPath']);
+ break;
+ }
+ $facedetector=new HAARDetector($haarcascade_frontalface_alt);
+ $facedetector->setImage($source_img,0.25);
+ // cannyPruning set to false since it does not produce expected results (maybe fix in the future)
+ $foundsth=$facedetector->detect(1, 1.25, 0.1, 1, false);
+ if ($foundsth)
+ {
+ $found=$facedetector->objects[0]; // take first found feature
+ $dest_img = imagecreatetruecolor($found['width'], $found['height']);
+ imagecopy($dest_img, $source_img, 0, 0, $found['x'], $found['y'], $found['width'], $found['height']);
+ switch($_SESSION['fileExt'][1]) {
+ case 'jpg': case 'jpeg':
+ imagejpeg($dest_img, $_SESSION['newPath']); break;
+ case 'gif':
+ imagegif($dest_img, $_SESSION['newPath']); break;
+ case 'png':
+ imagepng($dest_img, $_SESSION['newPath']); break;
+ }
+ header('Location: index.php');
+ }
+ else
+ {
+ $error .= '<br />Error: Nothing Found';
+ }
+}
+?>
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,29 @@
+<?php
+//set_time_limit ( 300 );
+error_reporting(E_ALL);
+session_start();
+require_once 'feature_detection.php';
+?>
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>HAAR Feature Detection with PHP GD</title>
+ <link rel="stylesheet" type="text/css" href="css.css" />
+ </head>
+ <body>
+ <h1>HAAR Face Detection with PHP GD</h1>
+ <?php if (isset($error)) echo "<p id='error'>".$error."</p>"; ?>
+ <?php //if (!isset($_SESSION['newPath']) || isset($_GET['new'])) { ?>
+ <form method='POST' action='index.php' id='imgForm' enctype='multipart/form-data'>
+ <label for='img_upload'>Image File: </label>
+ <input type='file' name='img_upload' id='img_upload'>
+ <label for='img_name'>Image Name: </label>
+ <input type='text' name='img_name' id='img_name'>
+ <input type='submit' value="Upload and Detect" name='upload_form_submitted'>
+ </form>
+ <?php //} else { ?>
+ <h2>Detected Features</h2>
+ <img id='uploaded_image' src='<?php echo $_SESSION['newPath'].'?'.rand(0, 100000); ?>' />
+ <?php //} ?>
+ </body>
+</html>
@@ -0,0 +1,29 @@
+HAARPHP Feature Detection Library for PHP
+
+based on Viola-Jones Feature Detection Algorithm using Haar Cascades
+
+This is a port of OpenCV C++ Haar Detection (actually a port of JViolaJones which is a port of OpenCV for Java)
+to PHP.
+
+You can use the openCV cascades to build your detectors.
+
+To do this just transform the opencv xml file to PHP
+using the haartophp tool (in cascades folder)
+
+example:
+( to use opencv's haarcascades_frontalface_alt.xml run following command)
+haartophp haarcascades_frontalface_alt
+
+this creates a php file:
+haarcascades_frontalface_alt.php which you can include in your php application
+
+the variable to use in php
+is similarly
+$haarcascades_frontalface_alt
+
+Examples included with face detection
+
+Complete source code
+
+*Author* Nikos M.
+*URL* http://nikos-web-development.netai.net/
Oops, something went wrong.

0 comments on commit f832c33

Please sign in to comment.