在c#xamarin中使用Vision OCR时。我发现该API返回的文本应该位于1个区域中的不同区域中。这会导致意外行为和错误的数据处理。
要解决此问题,Im需要从行的边界框中提取Y坐标,并保存随附的数据。 将两者都添加到列表中。 将每个列表条目与所有其他条目交叉引用。当两个Y坐标的偏差在10以内时,需要将它们合并。
我在代码结构下方添加了一个抄本。我尝试使用元组,字典,结构等。但是找不到交叉引用任何一个值的解决方案。
有人在正确的方向指向指针吗?
更新;我将递归二进制搜索与元组比较器结合使用取得了良好的进展。如果可以,我会发布代码。
class Playground
{
public void meh()
{
//these are the boundingboxes of different regions when the returned value from the OCR api is parsed
// int[] arr=new int[]{ Left X, Top Y, Width, Height};
int[] arrA =new int[] { 178, 1141, 393, 91 };//item 3 xenos
int[] arrB =new int[] { 171, 1296, 216, 53 };//totaal 3items
int[] arrC =new int[] { 1183, 1134, 105, 51};//item 3 prijs
int[] arrD =new int[] { 1192, 1287, 107, 52 };//totaal prijs
//the strings as will be made available within the lines, as words
string strA = "item 3";
string strB = "totaal:";
string strC = "2,99";
string strD = "8,97";
//make list to hold our fake linedata
List<int[]> ourLines = new List<int[]>();
ourLines.Add(arrA); ourLines.Add(arrB); ourLines.Add(arrC); ourLines.Add(arrD);
//following structure is observed
for(int region = 0; region < 3; region++){
//3 regions for each region process lines
foreach(int[] lineData in ourLines)
{
//get Y coordinates from boundingbox which is: lineData[1]
//keep int in memory and link* words in the corresponding line to it.
//put int and its words in array outside region loop.
//repeat this a couple of 100 times
for (int words = 0; words < 180; words++)
{
//do stuff with words
}
}
}
//here i need a list with the Y coordinates (for example 1141, 1296,1134, 1287)
//cross reference all Y coordinates with eachother
//when they fall withing a deviation of 10 with another
//then build string with combined text
//search in text for words resembing 'total' and check if there is an approperiate monetary value.
//the above would link the values of arrays A + C and B + D.
//which causes the corresponding results to be; 'item 3 2.99' and 'totaal 8.97'
//currently the arrays A+B are returned in region one and C+D in region two. This also varies from image to image.
//necessary because vision OCR api sometimes decides that lists of productname + price do belong in 2 different regions
//same for totals, and this causes incorrect responses when reading the data. (like thinking the amount of products == the price
//so if you bought 3 items the ocr will think the total price is 3$. instead of 8.97 (when each item is 2.99)
//note, values are monetary and culture independant. so this can mean the values can be in xx.xx or xx,xx
//* with link i mean either make a tuple/list/struct/keyvaluepair/dictionary/or preferably something more approperiate.
// this code will be executed on android and iOS devices.. something lightweight is preferred.
}
}