处理Computer Vision API的结果

时间:2018-01-23 18:43:03

标签: azure computer-vision artificial-intelligence azure-cognitive-services

我正在使用Azure Cognitive Services计算机视觉API,我遇到了解如何处理结果的问题。用例是我有一个图像,它是特定月份的事件日历的照片。我通过Computer Vision API OCR方法运行图像

https://eastus2.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc

获取一个JSON,它是区域,线条和单词的对象,每个区域都有边界。我很难找到一种方法去" group"这些项目成为所需的格式。以下是为此图像返回的示例JSON

https://drive.google.com/file/d/12dO0vIjGNQ8_nARTQbFHmaLNQNOWBC2x/view?usp=sharing

{ "textAngle": 0.0, "orientation": "NotDetected", "language": "en", "regions": [ { "boundingBox": "727,56,1692,119", "lines": [ { "boundingBox": "727,56,1692,119", "words": [ { "boundingBox": "727,57,727,118", "text": "CHILDREN!S" }, { "boundingBox": "1576,58,583,111", "text": "JANUARY" }, { "boundingBox": "2280,56,139,114", "text": "20" } ] } ] }, { "boundingBox": "361,265,159,42", "lines": [ { "boundingBox": "361,265,159,42", "words": [ { "boundingBox": "361,265,159,42", "text": "Sunday" } ] } ] }, { "boundingBox": "279,593,298,1261", "lines": [ { "boundingBox": "279,593,17,26", "words": [ { "boundingBox": "279,593,17,26", "text": "7" } ] }, { "boundingBox": "280,633,203,33", "words": [ { "boundingBox": "280,633,102,33", "text": "Library" }, { "boundingBox": "394,634,89,32", "text": "Open" } ] }, { "boundingBox": "282,675,124,32", "words": [ { "boundingBox": "282,675,7,26", "text": "1" }, { "boundingBox": "307,675,37,26", "text": "-5" }, { "boundingBox": "356,681,50,26", "text": "pm" } ] }, { "boundingBox": "280,716,252,31", "words": [ { "boundingBox": "280,716,71,25", "text": "New" }, { "boundingBox": "360,716,73,25", "text": "Year" }, { "boundingBox": "444,716,88,31", "text": "Open" } ] }, { "boundingBox": "281,757,96,26", "words": [ { "boundingBox": "281,757,96,26", "text": "House" } ] }, { "boundingBox": "280,797,297,27", "words": [ { "boundingBox": "280,797,67,27", "text": "Start" }, { "boundingBox": "357,797,55,26", "text": "The" }, { "boundingBox": "424,797,71,26", "text": "New" }, { "boundingBox": "503,797,74,26", "text": "Year" } ] }, { "boundingBox": "281,836,286,34", "words": [ { "boundingBox": "281,837,77,33", "text": "Right" }, { "boundingBox": "367,837,25,26", "text": "@" }, { "boundingBox": "401,837,51,26", "text": "the" }, { "boundingBox": "463,836,104,33", "text": "Library" } ] }, { "boundingBox": "281,878,110,32", "words": [ { "boundingBox": "281,878,48,26", "text": "1-5" }, { "boundingBox": "341,885,50,25", "text": "pm" } ] }, { "boundingBox": "282,976,34,25", "words": [ { "boundingBox": "282,976,34,25", "text": "14" } ] }, { "boundingBox": "281,1034,223,33", "words": [ { "boundingBox": "281,1034,103,33", "text": "Library" }, { "boundingBox": "395,1034,109,26", "text": "Closed" } ] } ] } ] }

我希望能够按日期对所有最低级别的单词进行分组,例如

7:图书馆下午1点到5点开放,    新年开放日开始新的一年@图书馆下午1-5点 14:图书馆关闭

有没有什么好的算法可以做这样的事情,或者是蛮力(检查每个文本的日期并在数组之间插入跨度)唯一的方法?如果有帮助,我可以将样本图像放在某处。

1 个答案:

答案 0 :(得分:0)

嗯,我认为你忽略了这个问题。我们无法使用数字作为基础进行排序。所以无论算法是什么,你仍然必须采取" date" out并将其用作分拣基地。

所以首先要创建一个字典,如下所示

{
    "text1": date1,
    "text2": date2,
 }

然后排序。而且你已经完成了