From 1a16b19acb23a4f28bafd01f3ed80fb225a96c3e Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 30 九月 2022 18:04:12 +0800 Subject: [PATCH] 'bug修复' --- ConsoleApplication/kernel.cl | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 100 insertions(+), 16 deletions(-) diff --git a/ConsoleApplication/kernel.cl b/ConsoleApplication/kernel.cl index 8f523d0..893640c 100644 --- a/ConsoleApplication/kernel.cl +++ b/ConsoleApplication/kernel.cl @@ -116,6 +116,8 @@ //只能识别4种数字 unsigned char type = types[index % ele_count_per_line]; //printf("ele_count_line:%d\n", ele_count_line); + //是否只有一位小数 + bool one_point_num = false; //时间 if (type == 0) { //时间 @@ -220,7 +222,9 @@ //查找单位前的空格 int num_end = -1; int i; - for (i = endx - 11;i >= startx;i--) { + //获取是否有单位 + int last_empty_index = -1; + for (i = endx;i >= startx;i--) { bool empty = 1; for (int y = starty;y < endy;y++) { if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { @@ -229,8 +233,29 @@ } } if (empty) { - num_end = i - 1; + last_empty_index = i; break; + } + } + bool hasUnit = false; + if (endx - last_empty_index > num_width) { + hasUnit = true; + } + + //带有单位 + if (hasUnit) { + for (i = endx - 11;i >= startx;i--) { + bool empty = 1; + for (int y = starty;y < endy;y++) { + if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { + empty = 0; + break; + } + } + if (empty) { + num_end = i - 1; + break; + } } } @@ -327,10 +352,19 @@ if (m_s == -1 || m_e == -1) { //printf("没找到小数点:%d", index); - nps[0] = -1; - nps[1] = -1; - nps[2] = -1; - nps[3] = -1; + if (hasUnit) + { + nps[0] = -1; + nps[1] = -1; + nps[2] = -1; + nps[3] = -1; + } + else { + nps[0] = startx; + nps[1] = starty; + nps[2] = endx; + nps[3] = endy; + } nps[4] = -1; nps[5] = -1; @@ -350,6 +384,9 @@ nps[5] = starty; nps[6] = num_end; nps[7] = endy; + if (nps[6] - nps[4] + 1 <= num_width) { + one_point_num = true; + } } nps[8] = -1; @@ -454,7 +491,7 @@ } //百分比 else if (type == 5) { - + //百分比数字起始位置 int percent_start = -1; int emptyIndex = -1; @@ -469,18 +506,19 @@ } if (empty) { emptyIndex = i; - }else if (emptyIndex > 0) { + } + else if (emptyIndex > 0) { percent_start = i; break; } } - + //百分比数字的结束位置 int percent_end = -1; emptyIndex = -1; - + for (i = endx;i >= startx;i--) { bool empty = 1; for (int y = starty;y < endy;y++) { @@ -491,13 +529,14 @@ } if (empty) { emptyIndex = i; - }else if (emptyIndex > 0) { + } + else if (emptyIndex > 0) { percent_end = i; break; } } - + if (percent_start > -1) { startx = percent_start; @@ -507,7 +546,7 @@ endx = percent_end; } - + //按照价格的形式做识别 int m_s = -1, m_e = -1; uchar temp[8]; @@ -546,7 +585,7 @@ } if (m_s == -1 || m_e == -1) { - + nps[0] = -1; nps[1] = -1; nps[2] = -1; @@ -636,7 +675,7 @@ } } - int zeroCount = length_per_num - numCount; + int zeroCount = length_per_num - numCount - (one_point_num?1:0); //最大为20位数 int fresult[20 * 2]; for (i = 0;i < zeroCount;i++) { @@ -647,6 +686,11 @@ for (i = 0;i < numCount;i++) { fresult[(i + zeroCount) * 2] = numberCols[i * 2]; fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; + } + //一位小数需要在末尾填充0 + if (type == 1 && one_point_num) { + fresult[(numCount + zeroCount) * 2] = -1; + fresult[(numCount + zeroCount) * 2 + 1] = -1; } //开始填充数据 @@ -776,7 +820,10 @@ //只能识别4种数字 unsigned char type = types[index % ele_count_per_line]; //printf("ele_count_line:%d\n", ele_count_line); + //是否只有一位小数 + bool one_point_num = false; //时间 + if (type == 0) { //时间 int s = cols / 2; @@ -998,6 +1045,10 @@ nps[5] = starty; nps[6] = num_end; nps[7] = endy; + if (nps[6] - nps[4] <= num_width) { + //只有一个数字 + one_point_num = true; + } } @@ -1160,7 +1211,7 @@ } } - int zeroCount = length_per_num - numCount; + int zeroCount = length_per_num - numCount - (one_point_num?1:0); //最大为20位数 int fresult[20 * 2]; for (i = 0;i < zeroCount;i++) { @@ -1171,6 +1222,12 @@ for (i = 0;i < numCount;i++) { fresult[(i + zeroCount) * 2] = numberCols[i * 2]; fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; + } + + //TODO 如果是金额,且后面只有1位小数的,需要在末尾填充0 + if (type == 1&& one_point_num) { + fresult[(numCount + zeroCount) * 2] = -1; + fresult[(numCount + zeroCount) * 2 + 1] = -1; } //开始填充数据 @@ -2204,6 +2261,33 @@ int unit_start = -1; int i; + + //查询是否有单位 + //获取是否有单位 + int last_empty_index = -1; + for (i = endx;i >= startx;i--) { + bool empty = 1; + for (int y = starty;y < endy;y++) { + if (get_binary_value(imgs[get_one_level_position(width, i, y)]) > 0) { + empty = 0; + break; + } + } + if (empty) { + last_empty_index = i; + break; + } + } + bool hasUnit = false; + if (endx - last_empty_index > 6) { + hasUnit = true; + } + else { + //没有单位 + result[index] = 2; + return; + } + for (i = endx - 11;i >= startx;i--) { bool empty = 1; for (int y = starty;y < endy;y++) { -- Gitblit v1.8.0