Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
License Plate Recognition on Plate Recognizer of remote image without saving to a tmp file
{
"name": "l1",
"version": "1.0.0",
"description": "",
"main": "remote_img_recognizer.js",
"dependencies": {
"form-data": "^3.0.0",
"node-fetch": "^2.6.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
const fetch = require('node-fetch');
const FormData = require('form-data');
var http = require('https');
// If image url is http, use below
// var http = require('http');
function upload(base64Image){
let body = new FormData();
// body.append('upload', fs.createReadStream(image_path));
body.append('upload', base64Image);
body.append('regions', 'gb'); // Change to your country
fetch("https://api.platerecognizer.com/v1/plate-reader/", {
method: 'POST',
headers: {
"Authorization": "Token YourAPItoken"
},
body: body
}).then(res => res.json())
.then(json => console.log(json))
.catch((err) => {
console.log(err);
});
}
let imgUrl = 'https://user-images.githubusercontent.com/14224149/75100715-d4817080-55d1-11ea-9c64-2dae43df8fe8.png';
http.get(imgUrl, (resp) => {
resp.setEncoding('base64');
body = "data:" + resp.headers["content-type"] + ";base64,";
resp.on('data', (data) => { body += data});
resp.on('end', () => {
console.log(body);
// Upload base64
upload(body);
});
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment