ALPRBR tem precisão, é rápido e amigável ao desenvolvedorAPI de Reconhecimento Automático de Placas que funciona em todos os ambientes. Otimizado para uso no Brasil para reconhecer placas padrão Mercosul assim como as antigas ainda em uso. |
|||||||
Existem várias empresas oferecendo o serviço de informações relacionadas a veículos. O código abaixo foi desenvolvido para operar com a InfoSimples. Esta é uma das empresas que oferecem franquia para fins de testes para novas contas. Siga as instruções no link acima para receber as credenciais necessárias. De posse destas credenciais siga as instruções abaixo para obter dados dos veículos.
No lugar deste switch uma barreira Infravermelho pode ser usada. Em desenvolvimento: script PHP que salvará dados formatados para banco de dados MySQL.
| |||||||
|
<!DOCTYPE html> <html lang=""> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>ALPRBR Demo</title> </head> <body align='center' onload='startFunc()'> <div> <input type="file" name="file" id="file" onclick="startFunc()" > <input type="button" id="btn_uploadfile" value="Upload" onclick="uploadFile()" > </div> <br> <form name='alprbr' id='alprbr'> <table align='center' style="border-collapse: collapse;" border="1"> <tbody> <tr><td colspan='2' align='center'>Imagem Max 256K, jpg, jpeg e png</td></tr> <tr><td><label for="credits">Creditos</label></td> <td><input type='text' name='credits' id='credits'></td></tr> <tr><td>Placa</td><td><input type='text' name='property' id='property'></td></tr> <tr><td>Chassi_final</td><td><input type='text' name='chassi_final' id='chassi_final'> </td></tr> <tr><td>Cidade</td><td><input type='text' name='cidade' id='cidade'></td></tr> <tr><td>Estado</td><td><input type='text' name='uf' id='uf'></td></tr> <tr><td>Marca</td><td><input type='text' name='marca' id='marca'></td></tr> <tr><td>Modelo</td><td><input type='text' name='modelo' id='modelo'></td></tr> <tr><td>Ano</td><td><input type='text' name='ano' id='ano'></td></tr> <tr><td>Cor</td><td><input type='text' name='cor' id='cor'></td></tr> <tr><td>Situação</td><td><input type='text' name='situacao' id='situacao'></td></tr> <tr><td colspan="2"><img id="vehicle" src="" alt="VeÃculo" width="400"/></td></tr> </tbody> </table> </form> <script> // Upload file function startFunc(){ document.getElementById('vehicle').style.visibility = 'hidden'; } function uploadFile() { document.getElementById("vehicle").disabled = true; document.querySelector('#btn_uploadfile').value = 'Processando, Aguarde...'; document.getElementById("btn_uploadfile").disabled = true; var files = document.getElementById("file").files; if(files.length > 0 ){ var formData = new FormData(); formData.append("file", files[0]); var xhttp = new XMLHttpRequest(); // Set POST method and ajax file path xhttp.open("POST", "demoIS.php", true); // call on request changes state xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var response = this.responseText; if(response == ''){ alert("Erro no Upload."); }else{ //alert(response); const jsonData = JSON.parse(response); document.getElementById("credits").value = jsonData.credits; document.getElementById("property").value = jsonData.property; document.getElementById("chassi_final").value = jsonData.chassi_final; document.getElementById("cidade").value = jsonData.cidade; document.getElementById("uf").value = jsonData.uf; document.getElementById("marca").value = jsonData.marca; document.getElementById("modelo").value = jsonData.modelo; document.getElementById("ano").value = jsonData.ano; document.getElementById("cor").value = jsonData.cor; document.getElementById("situacao").value = jsonData.situacao; if(jsonData.counter!=''){ document.getElementById("vehicle").disabled = false; document.getElementById("vehicle").src = "https://SEUSERVIDOR/upload/"+ files[0].name; document.getElementById("vehicle").style.visibility = 'visible'; } document.querySelector('#btn_uploadfile').value = 'Upload'; document.getElementById("btn_uploadfile").disabled = false; } } }; // Send request with data xhttp.send(formData); }else{ alert("Please select a file"); } } </script> </body> </html> |
<?php //Credenciais ALPRBR $token = "Seu Token ALPRBR"; //Credenciais InfoSimples $login_cpf = "CPF cadastrado SINESP Cidadão"; $login_senha = "Senha cadastrado SINESP Cidadão"; $timeout = 300; $IStoken = "Seu Token para acesso no InfoSimples"; $ISurl = "http://api.infosimples.com/api/v2/consultas/sinesp/veiculo"; if(isset($_FILES['file']['name'])){ // file name $filename = $_FILES['file']['name']; // file size $file_size = $_FILES['file']['size']; // Location $location = 'upload/'.$filename; $imageUrl = 'https://SEUSERVIDOR/'.$location; // file extension $file_extension = pathinfo($location, PATHINFO_EXTENSION); $file_extension = strtolower($file_extension); // Valid image extensions $valid_ext = array("jpg","png","jpeg"); $response = 0; if(($file_size >= 262144) || ($file_size == 0)) { echo ('{"credits": "","property":"","chassi_final":"", "cidade":"","uf":"","marca":"","modelo":"","ano":"","cor":"", "situacao":"Imagem max = 256Kb"}'); die(); } if(in_array($file_extension,$valid_ext)){ // Upload file if(move_uploaded_file($_FILES['file']['tmp_name'],$location)){ //prepare post to alprbrapi $url = 'http://alprbr.com:30305/alprbr'; $data = array('imageurl' => $imageUrl, 'token' => $token, 'countrycode' => 'br'); // use key 'http' even if you send the request to https://... $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); $json = json_decode($result); if ($result === FALSE) { /* Handle error */ }else{ //var_dump($result); //echo $result; //prepare post to InfoSimples $params = array('placa' => $json->property, 'login_cpf' => $login_cpf, 'login_senha' => $login_senha, 'token' => $IStoken, 'timeout' => $timeout); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $ISurl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $params); $response_body = curl_exec($curl); $err = curl_error($curl); curl_close($curl); $IS = json_decode($response_body); echo ('{"credits": "'.$json->credits. '","property": "'.$json->property. '","chassi_final": "'.$IS->data[0]->chassi_final. '","cidade": "'.$IS->data[0]->cidade. '","uf": "'.$IS->data[0]->uf. '","marca": "'.$IS->data[0]->marca. '","modelo": "'.$IS->data[0]->modelo. '","ano": "'.$IS->data[0]->ano. '","cor": "'.$IS->data[0]->cor. '","situacao": "'.$IS->data[0]->situacao.'"}'); } //unlink($location); //delete uploaded file //echo $response; exit; } }else{ echo ('{"credits": "","property":"","chassi_final":"", "cidade":"","uf":"","marca":"","modelo":"","ano":"","cor":"", "situacao":"Imagens: jpg,jpeg e png"}'); } }else{ echo "noFile"; } ?> |