-
Notifications
You must be signed in to change notification settings - Fork 19
/
read_license_plate.js
56 lines (28 loc) · 1.27 KB
/
read_license_plate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
var fs = require('fs');
async function setEndpoint() {
// Specifies the location of the api endpoint
const clientOptions = { apiEndpoint: 'eu-vision.googleapis.com' };
// Creates a client
const client = new vision.ImageAnnotatorClient(clientOptions);
// Performs text detection on the image file
const [result] = await client.textDetection('./images/cali.jpg');
const labels = result.textAnnotations;
console.log('Text:');
// labels.forEach(label => console.log(label.description));
//console.log(labels);
labels.forEach(function (a, b) {
//console.log(a.description);
if (/[A-Z0-9]{5,}/.test(a.description)) {
// console.log(a.description.match(/[A-Z0-9]{5,}/));
var license_number = a.description.match(/[A-Z0-9]{5,}/)[0];
console.log(license_number);
var data = fs.readFileSync('./html/index.html', 'utf-8');
var newValue = data.replace(/class="license">.*?</gim, 'class="license">' + license_number + '<');
fs.writeFileSync('./html/index.html', newValue, 'utf-8');
console.log('readFileSync complete');
}
});
}
setEndpoint();