Created
July 23, 2020 12:06
-
-
Save danleyb2/7102ad5153f53364d27f3a3f104a839c to your computer and use it in GitHub Desktop.
License Plate Recognition on Plate Recognizer of remote image without saving to a tmp file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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