Exemplo n.º 1
0
function insert_urls($conn)
{
    $target_url = $_POST['t_url'];
    // t_url is taken from user input through the text box
    $html = new simple_html_dom();
    if (!$html->load_file($target_url)) {
        $i = 1;
        foreach ($html->find('img') as $image) {
            $image_url = $image->src;
            $pp_image = imagecreatefromstring(file_get_contents($image_url));
            imagejpeg($pp_image, 'temp_images/img' . $i . '.jpeg');
            // Saves the image as a jpeg file
            $detector = new svay\FaceDetector('detection.dat');
            if ($detector->faceDetect('temp_images/img' . $i . '.jpeg')) {
                // If the detector detects a face
                $sql = "INSERT INTO images (url) VALUES ('{$image_url}')";
                // Insert that url into the database
                $stmt = $conn->prepare($sql);
                $stmt->execute();
            }
            $i++;
        }
    } else {
        echo '<br /><div id="strongtext"><p><strong>Palun sisesta mõni muu aadress.</strong></p></div>';
        var_dump($html->load_file($target_url));
    }
    $temp_files = glob('temp_images/*');
    // After the foreach loop is done checking all of the images
    foreach ($temp_files as $temp_file) {
        if (is_file($temp_file)) {
            unlink($temp_file);
        }
    }
    echo '<script>alertFunction();</script>';
    // Alert the user that the script has finished working
}
 /**
  * The callback ran in the async request to do the face detection.
  *
  * @access private
  * @since  1.0
  * @static
  * @param  array  $atts   The associative array that is passed to an instance of cnImage::get() when processing an immage.
  * @param  string $source The image URL or absolute path. NOTE: The onl valid pathhs will be: WP_CONTENT/UPLOADS or STYLESHEETPATH
  * @param  string $return What to return, @see cnImage::get()
  *
  * @return void
  */
 public static function detect($atts, $source, $return)
 {
     if (!is_wp_error($info = cnImage::info($source))) {
         $name = $info['basename'];
         $cache = cnCache::get('face_detect', 'option-cache', 'cnfc');
         $image = $cache != FALSE ? json_decode($cache, TRUE) : array();
         if ($image == FALSE || (!isset($image[$name]) || $image[$name]['modified'] != $info['modified'])) {
             if (!class_exists('svay\\FaceDetector')) {
                 include_once CNFD_PATH . 'vendor/facedetector/FaceDetector.php';
             }
             $detect = new svay\FaceDetector();
             $detect->faceDetect($info['path']);
             $coord = $detect->getFace();
             if (!is_null($coord)) {
                 $atts['crop_focus'] = array(($coord['x'] + $coord['w'] / 2) / $info[0], $coord['y'] / $info[1]);
             }
             $image[$name]['path'] = $info['path'];
             $image[$name]['modified'] = $info['modified'];
             $image[$name]['mime'] = $info['mime'];
             $image[$name]['width'] = $info[0];
             $image[$name]['height'] = $info[1];
             $image[$name]['face'] = $coord;
             $image[$name]['crop_focus'] = $atts['crop_focus'];
             if (!is_wp_error($result = cnImage::get($source, $atts))) {
                 cnCache::set('face_detect', json_encode($image), YEAR_IN_SECONDS, 'option-cache', 'cnfc');
             }
         }
     }
 }
Exemplo n.º 3
0
<?php

include "FaceDetector.php";
$detector = new svay\FaceDetector('detection.dat');
$detector->faceDetect('lena512color.jpg');
$detector->toJpeg();
 public function DetectFace()
 {
     $detector = new svay\FaceDetector();
     $detector->faceDetect($this->owner->getFullPath());
     return $detector->getFace();
 }