-
Notifications
You must be signed in to change notification settings - Fork 0
/
pan_ocr.js
105 lines (97 loc) · 3.35 KB
/
pan_ocr.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
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
//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': 'key'
},
body: "{'url':'link'}",
};
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";
}
}
console.log(str);
console.log(str.indexOf("OF BIRTH"));
var arr = str.split("\n");
console.log(arr);
console.log(arr.indexOf("OF BIRTH"));
for (i = 0; i < arr.length; i++) {
arr[i] = trim(arr[i]);
}
for (i = 0; i < arr.length; i++) {
if (arr[i].indexOf("NUMBER") > -1) {
console.log("NUMBER is : ");
console.log(arr[i + 1]);
} else if (arr[i].indexOf("FATHER") > -1) {
console.log("Father's Name is : ");
console.log(arr[i + 1]);
if (arr[i + 2].indexOf("BIRTH") === -1) {
console.log(arr[i+2]);
}
} else if (arr[i].indexOf("NAME") > -1) {
console.log("NAME is : ");
console.log(arr[i + 1]);
if (arr[i + 2].indexOf("FATHER") === -1) {
console.log(arr[i+2]);
}
} else if (arr[i].indexOf("BIRTH") > -1) {
console.log("Birth is : ");
console.log(arr[i + 1]);
}
}
/*
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);