-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (42 loc) 路 1.34 KB
/
Copy pathserver.js
File metadata and controls
55 lines (42 loc) 路 1.34 KB
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
const port = process.env.PORT || 3000;
const { exec } = require("child_process");
const express = require("express");
var bodyParser = require('body-parser')
const app = express();
app.use(bodyParser.json())
app.get('/api/getLP/:imgID', (req, res) => {
var image = req.params.imgID;
exec(`wget https://i.imgur.com/${image}.jpg`);
exec(`alpr -c us -j ${image}.jpg`, (err, stdout, stderr) => {
try {
var output = JSON.parse(stdout).results[0].plate;
} catch (e) {
exec(`rm ${image}.jpg`);
res.json({ "license_plate": "NO PLATE DETECTED" });
};
if (output) {
console.log(`Got license plate ${output}`)
exec(`rm ${image}.jpg`);
res.json({ "license_plate": `${output}` });
};
});
//res.json(200);
});
app.get('/api/getCustomer/:LP', (req, res) => {
var LP = req.params.LP;
exec(`python3 fetch.py ${LP}`, (err, stdout, stderr) => {
try {
var output = stdout.split('\s');
} catch (e) {
res.json({ "user": "NOT FOUND." });
};
if (output) {
console.log(`Got customer ${output}`);
res.json({
"name": `${output[0]}`
});
};
});
//res.json(200);
});
app.listen(port, () => console.log("App started..."));