gpt4 book ai didi

javascript - 从 Vision API 文本检测中读取并填充适当的字段

转载 作者:行者123 更新时间:2023-11-30 09:48:25 25 4
gpt4 key购买 nike

一直在尝试从政府中读取数据。签发身份证并使用谷歌的 Vision Api 填写表格的字段,如下所示。

Government ID

我已经成功地从视觉 API 读取数据,但现在在填写表格时遇到问题,例如使用适当的数据......

Form

我怎样才能做到这一点?

What i Wish to get

Vision API 的响应:

{
"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 和 Microsoft 的计算机视觉 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 订阅 key 。如果您想使用自己的从 Google Vision API 生成的 JSON 文件,只需刮掉上面的代码并使用代码下部的算法。它会起作用! :) 干杯

关于javascript - 从 Vision API 文本检测中读取并填充适当的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37741299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com