Javascript 读取Vision API文本检测并填写相应字段
一直在尝试从政府颁发的身份证中读取数据,并使用谷歌的Vision Api填写如下表格中的字段 我已经成功地从vision API中读取了数据,但现在在填写表单时遇到了一些问题,如使用适当的数据填充表单 我怎样才能做到这一点 Vision API的回应:Javascript 读取Vision API文本检测并填写相应字段,javascript,html,ocr,vision,Javascript,Html,Ocr,Vision,一直在尝试从政府颁发的身份证中读取数据,并使用谷歌的Vision Api填写如下表格中的字段 我已经成功地从vision API中读取了数据,但现在在填写表单时遇到了一些问题,如使用适当的数据填充表单 我怎样才能做到这一点 Vision API的回应: { "responses": [ { "textAnnotations": [ { "locale": "en", "descrip
{
"responses": [
{
"textAnnotations": [
{
"locale": "en",
"description": "amagas faATST\nINCOME TAX DEPARTMENT\nMAHENDRAKUMARRBAGUL\nRAMKRISHNA NATTHU BAGUL\n01/06/1981\n4Permanent Account Number\nANSAB4834E\nSignature\nGOVT OF INDIA\n",
"boundingPoly": {
"vertices": [
{
"x": 2,
"y": 64
},
{
"x": 4308,
"y": 64
},
{
"x": 4308,
"y": 2701
},
{
"x": 2,
"y": 2701
}
]
}
},
{
"description": "amagas",
"boundingPoly": {
"vertices": [
{
"x": 6,
"y": 64
},
{
"x": 774,
"y": 65
},
{
"x": 774,
"y": 374
},
{
"x": 6,
"y": 373
}
]
}
},
请帮助您可以使用Node.js执行此操作。我是使用Node.js和微软的计算机视觉API完成的。获取JSON字符串后,将其解析为JSON对象并运行循环以从中提取数据。之后,使用split函数将数据存储到数组中
//Load the request module
var request = require('request');
var str="";
//Lets configure and request
request({
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':'xxxxxxxxxxxxxxxx'
},
body: "{'url':'LINK TO THE IMAGE'}",
}, function(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++){
var str = str + " "+ob.regions[i].lines[j].words[k].text;
}
str = str + "\n";
}
}
var arr = str.split("\n");
console.log("Name: " + arr[1]);
console.log("Father's Name: " + arr[2]);
console.log("Date of Birth: " + arr[3]);
console.log("Permanent Account Number: " + arr[5]);
}
});
只需在此应用程序中使用您自己的Microsoft Computer Vision API订阅密钥。如果您想使用从GoogleVisionAPI生成的JSON文件,只需划掉上面的代码并使用代码下面的算法即可。它会起作用的!:干杯您可以使用Node.js执行此操作。我是使用Node.js和微软的计算机视觉API完成的。获取JSON字符串后,将其解析为JSON对象并运行循环以从中提取数据。之后,使用split函数将数据存储到数组中
//Load the request module
var request = require('request');
var str="";
//Lets configure and request
request({
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':'xxxxxxxxxxxxxxxx'
},
body: "{'url':'LINK TO THE IMAGE'}",
}, function(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++){
var str = str + " "+ob.regions[i].lines[j].words[k].text;
}
str = str + "\n";
}
}
var arr = str.split("\n");
console.log("Name: " + arr[1]);
console.log("Father's Name: " + arr[2]);
console.log("Date of Birth: " + arr[3]);
console.log("Permanent Account Number: " + arr[5]);
}
});
只需在此应用程序中使用您自己的Microsoft Computer Vision API订阅密钥。如果您想使用从GoogleVisionAPI生成的JSON文件,只需划掉上面的代码并使用代码下面的算法即可。它会起作用的!:干杯根据您提供的样品,我们可以假设 1.部门和签名将在所有回复中提供给我们 2.您需要的所有信息都在单独的行中 基于这些假设: const regExpression=new Regex'/DEPARTMENT\\n.\\n签名/'; const str=response.responses[0]。textAnnotations[0]。description;//这将来自api响应表单vision 常量match=str.matchregExpression[2]。拆分“\\n”; /*上述脚本的输出如下所示 [ Mahendrakumarbagul, 拉姆克里希纳·纳图·巴格尔, 01/06/1981, 4永久账号, ANSAB4834E ]
*/ 根据您提供的样品,我们可以假设 1.部门和签名将在所有回复中提供给我们 2.您需要的所有信息都在单独的行中 基于这些假设: const regExpression=new Regex'/DEPARTMENT\\n.\\n签名/'; const str=response.responses[0]。textAnnotations[0]。description;//这将来自api响应表单vision 常量match=str.matchregExpression[2]。拆分“\\n”; /*上述脚本的输出如下所示 [ Mahendrakumarbagul, 拉姆克里希纳·纳图·巴格尔, 01/06/1981, 4永久账号, ANSAB4834E ]
*/我认为您应该使用样本pan卡图像或隐藏信息以保护Pramod Kumar MahtoI先生的隐私我认为您应该使用样本pan卡图像或隐藏信息以保护Pramod Kumar Mahto先生的隐私