-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
157 lines (127 loc) · 4.11 KB
/
app.js
File metadata and controls
157 lines (127 loc) · 4.11 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const express = require('express');
const app = express();
const fs = require('fs');
const multer = require('multer');
const path = require('path');
const tesseract = require("node-tesseract-ocr")
const lineReader = require('line-reader');
const hostname = '127.0.0.1';
const PORT = process.env.PORT || 4000;
let names;
const storage = multer.diskStorage(
{
destination: (req, file, cb) => {
console.log(file);
cb(null, 'images');
},
filename: (req, file, cb) => {
names = file.originalname;
cb(null, file.originalname)
}
}
)
const upload = multer({ storage: storage });
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'home.html'));
})
app.post('/', upload.single('image'), (req, res) => {
// console.log(req.upload);
const data = fs.readFileSync(`./images/${names}`);
const config = {
lang: "eng",
oem: 1,
psm: 3,
}
tesseract
.recognize(data, config)
.then((text) => {
console.log("Result:", text)
/*const nameIndex=text.indexOf("Name :") +6 ;
console.log(nameIndex)
const temp1=text.substring(0,nameIndex);
console.log(temp1);
const nameLength = temp1.split('\n').length ;
console.log(nameLength);
// console.log(text.startsWith('Name :'));
console.log(text.substring(nameIndex,nameIndex+nameLength).trim()); */
// For VOTER CARD
if (req.body.idType == 'voterid') {
//Extracting Voter id
const temp3=text.split('ELECTOR PHOTO IDENTITY CARD\r\n\r\n',2);
console.log(temp3);
const idind=temp3[1].indexOf('\r\n');
const Id=temp3[1].substring(idind -10,idind);
//Extracting personal info
const nameIndex = text.indexOf("Name :", 0);
console.log(nameIndex);
// console.log(text[184])
const temp1 = text.split("Name :", 2);
// console.log(temp1[1]);
const str1 = temp1[1].split("\r\n", 2);
const name = str1[0].trim();
const fatherIndex = text.indexOf("Father's ");
console.log(fatherIndex)
// console.log(fatherIndex,text[236])
const temp2 = text.split("Father's Name :", 2);
// console.log(temp2);
const str2 = temp2[1].split("\n", 2);
const fatherName = str2[0].trim();
res.json({
idType:'voterCard',
voterIdNumber:Id,
info:{
name: name,
fatherName: fatherName
}
});
} //For AADHAR CARD
else if (req.body.idType == 'aadharid') {
// Extracting personal info
const nameIndex = text.indexOf("DOB: ", 0);
console.log(nameIndex);
const temp1 = text.split("DOB: ", 2);
const lastind = temp1[0].lastIndexOf('\r\n\r\n');
const str2 = temp1[0].substring(0, lastind);
const begin = str2.lastIndexOf('\r\n') + 2;
console.log(begin);
const Name = temp1[0].substring(begin, lastind)
const str1 = temp1[1].split("\r\n", 2);
const dobstr = str1[0].trim();
const str3 = str1[1].split('/ ', 2);
const genderstr = str3[1].split('\r\n', 2);
const gender = genderstr[0];
const dob = dobstr;
//Extracting VID and AAdhar number
const vid = text.split('VID', 2);
const endind = vid[1].indexOf('\r\n');
const strind = vid[1].indexOf(': ') + 2;
const Vid=vid[1].substring(strind, endind);
const endind2 = vid[0].lastIndexOf('\r\n\r\n');
const aadharNum = vid[0].substring(endind2 - 14, endind2);
res.json({
idType: 'aadharCard',
aadharNumber: aadharNum,
vId:Vid,
info: {
name: Name,
dob: dob,
gender: gender
}
})
}
else if(req.body.idType=='drivingL')
{
console.log(text);
}
else if(req.body.idType=='pancard')
{
console.log(text);
}
}).catch((error) => {
console.log(error.message)
// res.send("DONE");
})
})
app.listen(PORT, () => {
console.log(`Server listening at port http://${hostname}:${PORT}`)
})