-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocrr.js~
79 lines (70 loc) · 2.7 KB
/
ocrr.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//Load the request module
var request = require('request');
var trim = require('trim');
var tempstr="";
var str="";
//Lets configure and request
var options = {
url: 'https://api.projectoxford.ai/vision/v1.0/ocr?', //URL to hit
qs: {"language": "unk",
"detectOrientation ": "true"
}, //Query string data
method: 'POST', //Specify the method
headers: { //We can define headers too
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key':'5f99789bf19f45e2b6c19b6264d3ecf9'
},
body: "{'url':'https://kuverabucket.s3.amazonaws.com/23t08w8un5dk5tw55uj5johbutvcfxsbslnl95qt03d51k6cph_IMG_20160613_201710_1465829267634.jpg'}",
};
function callback(error, response, body){
if(error) {
console.log(error);
} else {
var jsonObj = JSON.parse(body);
var ob = jsonObj;
for(i=0;i<ob.regions.length;i++){
for(j=0;j<ob.regions[i].lines.length;j++){
for(k=0;k<ob.regions[i].lines[j].words.length;k++){
str = str + " "+ob.regions[i].lines[j].words[k].text;
}
str = str +"\n";
}
}
var arr = str.split("\n");
for(i=0; i<arr.length; i++){
arr[i] = trim(arr[i]);
}
if(arr.length==11){
console.log("Name:"+ arr[1]+" "+ arr[2]);
console.log("Father's name:"+arr[3]+" "+arr[4]);
console.log("Date of birth:"+arr[5]);
console.log("PAN:" + arr[7]);
}
else if(arr.length==9){
console.log("Name:"+ arr[1]);
console.log("Father's name:"+arr[2]);
console.log("Date of birth:"+arr[3]);
console.log("PAN:" + arr[5]);
}
else if(arr.length==10){
if(arr[1].length>arr[2].length){
console.log("Name:"+ arr[1]+" "+arr[2]);
console.log("Father's name:"+arr[3]);
}
else{
console.log("Name:"+ arr[1]);
console.log("Father's name:"+arr[2]+" "+arr[3]);
}
console.log("Date of birth:"+arr[4]);
console.log("PAN:" + arr[6]);
}
else{
console.log("Image not of proper quality!");
console.log("Name:"+ arr[1]);
console.log("Father's name:"+arr[2]);
console.log("Date of birth:"+arr[3]);
console.log("PAN:" + arr[5]);
}
}
};
request(options, callback);