Example #1
0
function processSubmitClass()
{
    $success = 0;
    $msg = "Missing fields";
    if (isset($_POST["name"]) && !empty($_POST["name"]) && isset($_POST["subclass"]) && is_numeric($_POST["subclass"]) && $_POST["subclass"] > 0 && isset($_FILES["file"]["name"])) {
        $name = $_POST["name"];
        $subclass_id = $_POST["subclass"];
        $target_dir = "images/signs/classes/";
        $target_file = $target_dir . basename($_FILES["file"]["name"]);
        $image_file_type = pathinfo($target_file, PATHINFO_EXTENSION);
        $check = getimagesize($_FILES["file"]["tmp_name"]);
        if ($check !== false) {
            $msg = "File is an image - " . $check["mime"] . ".";
            $success = 1;
        } else {
            $msg = "File is not an image.";
            $success = 0;
        }
        // Check file size
        if ($_FILES["file"]["size"] > 500000) {
            $msg = "Sorry, your file is too large.";
            $success = 0;
        }
        // Check if file already exists
        if (file_exists($target_file)) {
            $msg = "Sorry, file already exists.";
            $success = 0;
        }
        // Allow certain file formats
        if ($image_file_type != "jpg" && $image_file_type != "png" && $image_file_type != "jpeg" && $image_file_type != "gif") {
            $msg = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $success = 0;
        }
        if (!$success) {
            $msg = "Sorry, your file was not uploaded.";
        } else {
            $file_name = uniqid('img_') . "." . $image_file_type;
            if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_dir . $file_name)) {
                $msg = "The file " . basename($_FILES["file"]["name"]) . " has been uploaded.";
                $class = new TrafficSignClass();
                $class->name = $name;
                $class->image = $file_name;
                $class->subclass_id = $subclass_id;
                $class->save();
            } else {
                $msg = "Sorry, there was an error uploading your file.";
            }
        }
    }
    return array("success" => $success, "msg" => $msg);
}
Example #2
0
function saveClasses($classes, $subclass)
{
    foreach ($classes as $class) {
        //Download image
        $file_name = uniqid('img_') . ".png";
        $file_path = "images/signs/classes/" . $file_name;
        file_put_contents($file_path, file_get_contents($class['image']));
        //Save class in db
        $image_class = new TrafficSignClass();
        $image_class->spain_id = $class['spain_id'];
        $image_class->name = $class['text'];
        $image_class->image = $file_name;
        $image_class->subclass_id = $subclass;
        $image_class->save();
    }
}
function recommendSampleClass()
{
    $response = ["success" => 0, "id" => 0, "msg" => "Unknown class", "image" => ""];
    if (isset($_POST["sample"]) && is_numeric($_POST["sample"]) && $_POST["sample"] > 0) {
        $sample = AnnotationSample::find($_POST["sample"]);
        if ($sample) {
            $client = new Client(["base_uri" => "http://alvaroarcos.co:8080/classify-ts/"]);
            $svm_class_id = intval($client->get("germany/" . $sample->image)->getBody()->getContents());
            if ($svm_class_id >= 0) {
                $class = TrafficSignClass::where('germany', $svm_class_id)->first();
                if ($class) {
                    $response = ["success" => 1, "id" => $class->id, "msg" => "Class predicted", "image" => $class->image];
                }
            }
        }
    }
    return json_encode($response);
}
function classifyMany($classify_many_id, $image_list)
{
    ini_set('memory_limit', '512M');
    $client = new GuzzleHttp\Client();
    $digits_response = $client->post('http://arcos.io:5000/models/images/classification/classify_many.json', ['multipart' => [['name' => 'job_id', 'contents' => '20161024-081150-5437'], ['name' => 'image_list', 'contents' => fopen($image_list, 'r')]]]);
    if ($digits_response->getStatusCode() == 200) {
        $digits_classifications = json_decode($digits_response->getBody())->classifications;
        $traffic_signs = array();
        foreach ($digits_classifications as $image => $classifications) {
            $classification = $classifications[0];
            $spain_id = $classification[0];
            $confidence = $classification[1];
            if (array_key_exists($spain_id, $traffic_signs)) {
                $traffic_sign = $traffic_signs[$spain_id];
            } else {
                $traffic_sign = TrafficSignClass::where('spain_id', '=', $spain_id)->first();
                $traffic_signs[$spain_id] = $traffic_sign;
            }
            $classify_many_sample = new ClassifyManySample();
            $classify_many_sample->sample_image = basename($image);
            $classify_many_sample->class_id = $traffic_sign['id'];
            $classify_many_sample->confidence = $confidence;
            $classify_many_sample->classify_many_id = $classify_many_id;
            $classify_many_sample->save();
        }
        return $digits_classifications;
    } else {
        return null;
    }
}
foreach ($sources as $source) {
    $html = file_get_contents($source['url']);
    $dom = new DOMDocument();
    @$dom->loadHtml($html);
    $xpath = new DOMXPath($dom);
    $texts = $xpath->query($source['text_query']);
    for ($i = 0; $i < $texts->length; $i++) {
        if (isset($source['is_table']) && $source['is_table']) {
            $sign_id = trim(strip_tags(html_entity_decode(scrape_between(getInnerHTML($texts->item($i)), '<br>', '</b>'))));
            $sign_text = trim(strip_tags(html_entity_decode(scrape_between(getInnerHTML($texts->item($i)), '<b>', '<br>'))));
        } else {
            $sign_id = trim(strip_tags(html_entity_decode(scrape_between(getInnerHTML($texts->item($i)), '<b>', '<br>'))));
            $sign_text = trim(strip_tags(html_entity_decode(scrape_between(getInnerHTML($texts->item($i)), '<br>', '</center>'))));
        }
        echo "Scraped: " . $sign_id . " - " . $sign_text . "<br>";
        $classes = TrafficSignClass::where('name', 'like', $sign_text . '%')->get();
        echo "<br><b>Matches in db [" . $classes->count() . "]:</b>";
        echo "<ul>";
        foreach ($classes as $class) {
            // Save traffic sign spanish id in db
            $sign_id = str_replace(' ', '', $sign_id);
            if (empty($sign_id)) {
                $sign_id = NULL;
            }
            $class->spain_id = $sign_id;
            $class->save();
            echo "<li>" . $class->name . " - id saved in db</li>";
        }
        echo "</ul>";
        echo "---------------<br>";
    }
Example #6
0
echo isset($sample) ? $sample->id : '-1';
?>
" class="waves-effect waves-light btn-large"><i class="material-icons left">check_circle</i>Save</a>
                <a id="recommend_sample_btn" style="margin-top: 15px;" class="waves-effect waves-light btn-large orange"><i class="material-icons left">help</i>Help me</a>
                <form>
                    <div class="input-field">
                        <input id="search" type="search">
                        <label for="search"><i class="material-icons">search</i></label>
                        <i class="material-icons">close</i>
                    </div>
                </form>
            </div>
            <div class="col s9 offset-s3">
                <?php 
foreach ($subclasses as $subclass) {
    $classes = TrafficSignClass::where('subclass_id', $subclass->id)->get();
    ?>
                    <h5 class="blue-grey-text text-lighten-1"><?php 
    echo $subclass->name;
    ?>
</h5>
                    <div class="card">
                        <div class="card-content">
                            <?php 
    $i = 0;
    foreach ($classes as $class) {
        $class_image_path = DIR_SIGNS_CLASSES . $class->image;
        if ($i % 6 == 0) {
            echo "<div class='row'>";
        }
        ?>