| | |
| | | int p = get_global_id(0); |
| | | int startIndex = p / width * width * num_width * num_height + p % (num_count * 10) * num_width; |
| | | unsigned char t = 0; |
| | | for (int r = 0;r < num_height;r++) |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = 0; r < num_height; r++) |
| | | for (int c = 0; c < num_width; c++) { |
| | | int index = startIndex + num_width * width * r + c; |
| | | t += abs(a_in[index] - b_in[index]); |
| | | if (p == 0) { |
| | |
| | | int min = 255; |
| | | int minIndex = 11; |
| | | |
| | | for (int i = startIndex;i < endIndex;i++) |
| | | for (int i = startIndex; i < endIndex; i++) |
| | | { |
| | | if (a_in[i] < min) { |
| | | min = a_in[i]; |
| | |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty;y <= endy;y++) { |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | } |
| | | } |
| | | |
| | | for (y = endy;y >= starty;y--) { |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | //往前查找冒号 |
| | | int m1_s = -1, m1_e = -1, m2_s = -1, m2_e = -1; |
| | | uchar temp[10]; |
| | | for (i = s;i > -1;i--) { |
| | | for (i = s; i > -1; i--) { |
| | | if (i < 5) { |
| | | break; |
| | | } |
| | |
| | | |
| | | //往后查找冒号 |
| | | |
| | | for (i = s;i < cols;i++) { |
| | | for (i = s; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | int i; |
| | | //获取是否有单位 |
| | | int last_empty_index = -1; |
| | | for (i = endx;i >= startx;i--) { |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | 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 (hasUnit) { |
| | | for (i = endx - 11;i >= startx;i--) { |
| | | for (i = endx - 11; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty;y <= endy;y++) { |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | } |
| | | } |
| | | |
| | | for (y = endy;y >= starty;y--) { |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy - 1;y++) { |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | int i; |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy - 1;y++) { |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int percent_start = -1; |
| | | int emptyIndex = -1; |
| | | int i; |
| | | for (i = startx;i <= endx;i++) { |
| | | for (i = startx; i <= endx; i++) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int percent_end = -1; |
| | | emptyIndex = -1; |
| | | |
| | | for (i = endx;i >= startx;i--) { |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | //按照价格的形式做识别 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[8]; |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy - 1;y++) { |
| | | for (int y = starty; y < endy - 1; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | |
| | | } |
| | | |
| | | //手数,带有单位手 |
| | | else if (type == 6) { |
| | | //分隔手 |
| | | int num_end = endx; |
| | | int emptyIndex=-1; |
| | | int i; |
| | | 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) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | emptyIndex = i; |
| | | } |
| | | else if (emptyIndex > 0) { |
| | | num_end = i; |
| | | break; |
| | | } |
| | | } |
| | | endx = num_end; |
| | | //去除上下空白 |
| | | int startNy = -1; |
| | | int endNy = -1; |
| | | int y; |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | startNy = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | | //有数据 |
| | | if (value > 0) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endNy = y; |
| | | break; |
| | | } |
| | | } |
| | | if (endNy > 0) |
| | | { |
| | | endy = endNy; |
| | | } |
| | | if (startNy > 0) |
| | | { |
| | | starty = startNy; |
| | | } |
| | | nps[0] = startx; |
| | | nps[1] = starty; |
| | | nps[2] = endx; |
| | | nps[3] = endy; |
| | | |
| | | nps[4] = -1; |
| | | nps[5] = -1; |
| | | nps[6] = -1; |
| | | nps[7] = -1; |
| | | |
| | | nps[8] = -1; |
| | | nps[9] = -1; |
| | | nps[10] = -1; |
| | | nps[11] = -1; |
| | | } |
| | | |
| | | //分隔数据 |
| | | |
| | | |
| | |
| | | int numberCols[20 * 2]; |
| | | |
| | | int i; |
| | | for (i = 0;i < 3;i++) { |
| | | for (i = 0; i < 3; i++) { |
| | | if (nps[i * 4] == -1) { |
| | | break; |
| | | } |
| | |
| | | |
| | | |
| | | int c, startC = -1, endC = -1; |
| | | for (c = 0;c < _cols;c++) { |
| | | for (c = 0; c < _cols; c++) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = _starty;y <= _endy;y++) { |
| | | for (int y = _starty; y <= _endy; y++) { |
| | | unsigned char value = get_binary_value(img_in[get_one_level_position(width, _startx + c, y)]); |
| | | if (value > 0) { |
| | | empty = 0; |
| | |
| | | } |
| | | } |
| | | |
| | | int zeroCount = length_per_num - numCount - (one_point_num?1:0); |
| | | int zeroCount = length_per_num - numCount - (one_point_num ? 1 : 0); |
| | | //最大为20位数 |
| | | int fresult[20 * 2]; |
| | | for (i = 0;i < zeroCount;i++) { |
| | | for (i = 0; i < zeroCount; i++) { |
| | | fresult[i * 2] = -1; |
| | | fresult[i * 2 + 1] = -1; |
| | | } |
| | | |
| | | for (i = 0;i < numCount;i++) { |
| | | for (i = 0; i < numCount; i++) { |
| | | fresult[(i + zeroCount) * 2] = numberCols[i * 2]; |
| | | fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; |
| | | } |
| | |
| | | } |
| | | |
| | | //开始填充数据 |
| | | for (i = 0;i < length_per_num;i++) { |
| | | for (i = 0; i < length_per_num; i++) { |
| | | |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = get_binary_value(zero[r * num_width + c]); |
| | | //设置输出坐标的值 |
| | | numData[r * num_width + c] = value; |
| | |
| | | else { |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty;r <= endy;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = starty; r <= endy; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | |
| | | //行偏移量 |
| | | int index_2 = (num_width * 10) * (length_per_num * (index % ele_count_per_line) + i); |
| | | |
| | | for (int re = 0;re < 10;re++) { |
| | | for (int re = 0; re < 10; re++) { |
| | | int index_3 = re * num_width; |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | int index_1 = r * (num_width * 10 * num_count); |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d value:%d \n", index, findex, numData[r * num_width + c]); |
| | | result[findex] = numData[r * num_width + c]; |
| | |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty;y <= endy;y++) { |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | } |
| | | } |
| | | |
| | | for (y = endy;y >= starty;y--) { |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | //是否只有一位小数 |
| | | bool one_point_num = false; |
| | | //时间 |
| | | |
| | | |
| | | if (type == 0) { |
| | | //时间 |
| | | int s = cols / 2; |
| | |
| | | //往前查找冒号 |
| | | int m1_s = -1, m1_e = -1, m2_s = -1, m2_e = -1; |
| | | uchar temp[7]; |
| | | for (i = s;i > -1;i--) { |
| | | for (i = s; i > -1; i--) { |
| | | if (i < 6) { |
| | | break; |
| | | } |
| | |
| | | |
| | | //往后查找冒号 |
| | | |
| | | for (i = s;i < cols;i++) { |
| | | for (i = s; i < cols; i++) { |
| | | if (i > cols - 6) { |
| | | break; |
| | | } |
| | |
| | | //查找单位前的空格 |
| | | int num_end = -1; |
| | | int i; |
| | | for (i = endx - 9;i >= startx;i--) { |
| | | for (i = endx - 9; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty;y <= endy;y++) { |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | } |
| | | } |
| | | |
| | | for (y = endy;y >= starty;y--) { |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | //查找小数点 |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[6]; |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | if (temp[2] > 0) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | nps[6] = num_end; |
| | | nps[7] = endy; |
| | | if (nps[6] - nps[4] <= num_width) { |
| | | //只有一个数字 |
| | | //只有一个数字 |
| | | one_point_num = true; |
| | | } |
| | | |
| | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[6]; |
| | | int i; |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | if (temp[2] > 0) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int numberCols[20 * 2]; |
| | | |
| | | int i; |
| | | for (i = 0;i < 3;i++) { |
| | | for (i = 0; i < 3; i++) { |
| | | if (nps[i * 4] == -1) { |
| | | break; |
| | | } |
| | |
| | | |
| | | |
| | | int c, startC = -1, endC = -1; |
| | | for (c = 0;c < _cols;c++) { |
| | | for (c = 0; c < _cols; c++) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = _starty;y <= _endy;y++) { |
| | | for (int y = _starty; y <= _endy; y++) { |
| | | unsigned char value = get_binary_value(img_in[get_one_level_position(width, _startx + c, y)]); |
| | | if (value > 0) { |
| | | empty = 0; |
| | |
| | | } |
| | | } |
| | | |
| | | int zeroCount = length_per_num - numCount - (one_point_num?1:0); |
| | | int zeroCount = length_per_num - numCount - (one_point_num ? 1 : 0); |
| | | //最大为20位数 |
| | | int fresult[20 * 2]; |
| | | for (i = 0;i < zeroCount;i++) { |
| | | for (i = 0; i < zeroCount; i++) { |
| | | fresult[i * 2] = -1; |
| | | fresult[i * 2 + 1] = -1; |
| | | } |
| | | |
| | | for (i = 0;i < numCount;i++) { |
| | | 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) { |
| | | if (type == 1 && one_point_num) { |
| | | fresult[(numCount + zeroCount) * 2] = -1; |
| | | fresult[(numCount + zeroCount) * 2 + 1] = -1; |
| | | } |
| | | |
| | | //开始填充数据 |
| | | for (i = 0;i < length_per_num;i++) { |
| | | for (i = 0; i < length_per_num; i++) { |
| | | |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = get_binary_value(zero[r * num_width + c]); |
| | | //设置输出坐标的值 |
| | | numData[r * num_width + c] = value; |
| | |
| | | else { |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty;r <= endy;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = starty; r <= endy; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | |
| | | //行偏移量 |
| | | int index_2 = (num_width * 10) * (length_per_num * (index % ele_count_per_line) + i); |
| | | |
| | | for (int re = 0;re < 10;re++) { |
| | | for (int re = 0; re < 10; re++) { |
| | | int index_3 = re * num_width; |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | int index_1 = r * (num_width * 10 * num_count); |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d value:%d \n", index, findex, numData[r * num_width + c]); |
| | | result[findex] = numData[r * num_width + c]; |
| | |
| | | temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]); |
| | | temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]); |
| | | temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]); |
| | | if (temp[2] > 0 && temp[3] > 0 ) { |
| | | if (temp[2] > 0 && temp[3] > 0) { |
| | | |
| | | if (temp[0] + temp[1] + temp[4] + temp[5] + temp[6] + temp[7] == 0) |
| | | { |
| | |
| | | int endNy = -1; |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = starty;y <= endy;y++) { |
| | | for (y = starty; y <= endy; y++) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | } |
| | | } |
| | | |
| | | for (y = endy;y >= starty;y--) { |
| | | for (y = endy; y >= starty; y--) { |
| | | bool empty = 1; |
| | | for (int x = startx;x <= endx;x++) |
| | | for (int x = startx; x <= endx; x++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | //往前查找冒号 |
| | | int m1_s = -1, m1_e = -1, m2_s = -1, m2_e = -1; |
| | | uchar temp[7]; |
| | | for (i = s;i > -1;i--) { |
| | | for (i = s; i > -1; i--) { |
| | | if (i < 6) { |
| | | break; |
| | | } |
| | |
| | | |
| | | //往后查找冒号 |
| | | |
| | | for (i = s;i < cols;i++) { |
| | | for (i = s; i < cols; i++) { |
| | | if (i > cols - 6) { |
| | | break; |
| | | } |
| | |
| | | if (startx > 0 && endx > 0) { |
| | | //分隔s/m/h |
| | | int emptyX = -1; |
| | | for (int x = endx;x >= startx;x--) { |
| | | for (int x = endx; x >= startx; x--) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y <= endy;y++) |
| | | for (int y = starty; y <= endy; y++) |
| | | { |
| | | int p = get_one_level_position(width, x, y); |
| | | unsigned char value = get_binary_value(img_in[p]); |
| | |
| | | int m_s = -1, m_e = -1; |
| | | uchar temp[6]; |
| | | int i; |
| | | for (i = 0;i < cols;i++) { |
| | | for (i = 0; i < cols; i++) { |
| | | if (i > cols - 5) { |
| | | break; |
| | | } |
| | |
| | | if (temp[2] > 0) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int numberCols[12]; |
| | | |
| | | int i; |
| | | for (i = 0;i < 3;i++) { |
| | | for (i = 0; i < 3; i++) { |
| | | if (nps[i * 4] == -1) { |
| | | break; |
| | | } |
| | |
| | | |
| | | |
| | | int c, startC = -1, endC = -1; |
| | | for (c = 0;c < _cols;c++) { |
| | | for (c = 0; c < _cols; c++) { |
| | | |
| | | bool empty = 1; |
| | | for (int y = _starty;y <= _endy;y++) { |
| | | for (int y = _starty; y <= _endy; y++) { |
| | | unsigned char value = get_binary_value(img_in[get_one_level_position(width, _startx + c, y)]); |
| | | if (value > 0) { |
| | | empty = 0; |
| | |
| | | int zeroCount = maxNumberCount - numCount; |
| | | |
| | | int fresult[6 * 2]; |
| | | for (i = 0;i < zeroCount;i++) { |
| | | for (i = 0; i < zeroCount; i++) { |
| | | fresult[i * 2] = -1; |
| | | fresult[i * 2 + 1] = -1; |
| | | } |
| | | |
| | | for (i = 0;i < numCount;i++) { |
| | | for (i = 0; i < numCount; i++) { |
| | | fresult[(i + zeroCount) * 2] = numberCols[i * 2]; |
| | | fresult[(i + zeroCount) * 2 + 1] = numberCols[i * 2 + 1]; |
| | | } |
| | | |
| | | //开始填充数据 |
| | | for (i = 0;i < maxNumberCount;i++) { |
| | | for (i = 0; i < maxNumberCount; i++) { |
| | | |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = get_binary_value(zero[r * num_width + c]); |
| | | //设置输出坐标的值 |
| | | numData[r * num_width + c] = value; |
| | |
| | | else { |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty;r <= endy;r++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int r = starty; r <= endy; r++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | |
| | | index_2 += (num_width * 10) * (6 + 2 + 6 + i); |
| | | } |
| | | |
| | | for (int re = 0;re < 10;re++) { |
| | | for (int re = 0; re < 10; re++) { |
| | | int index_3 = re * num_width; |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | int index_1 = r * (num_width * 10 * num_count); |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d \n",index, findex); |
| | | result[findex] = numData[r * num_width + c]; |
| | |
| | | int inLineDataCount = num_width * NUMBER_COUNT * LINE_NUMBER_COUNT; |
| | | |
| | | int outLineCount = outLineDataCount * gid; |
| | | for (int re = 0;re < LINE_NUMBER_COUNT;re++) { |
| | | for (int n = 0;n < NUMBER_COUNT;n++) |
| | | for (int re = 0; re < LINE_NUMBER_COUNT; re++) { |
| | | for (int n = 0; n < NUMBER_COUNT; n++) |
| | | { |
| | | int index_num_0 = n * num_width * num_height; |
| | | for (int r = 0;r < num_height;r++) { |
| | | for (int r = 0; r < num_height; r++) { |
| | | int intLineCount = inLineDataCount * r; |
| | | |
| | | for (int c = 0;c < num_width;c++) { |
| | | for (int c = 0; c < num_width; c++) { |
| | | int index_num = index_num_0 + r * num_width + c; |
| | | unsigned char value = numbers[index_num]; |
| | | int index = outLineCount; |
| | |
| | | |
| | | int startRowDataIndex = 7 * 4 * gid; |
| | | |
| | | for (int i = startCol;i <= endCol;i++) { |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | |
| | | bool empty = 1; |
| | | for (int j = startRow;j <= endRow;j++) { |
| | | for (int j = startRow; j <= endRow; j++) { |
| | | unsigned char value = imgs[get_one_level_position(width, i, j)]; |
| | | if (value >= 64) { |
| | | empty = 0; |
| | |
| | | } |
| | | |
| | | int emptyCount = 0; |
| | | for (int i = 0;i < 7;i++) { |
| | | for (int i = 0; i < 7; i++) { |
| | | if (i == emptyColIndex1 || i == emptyColIndex2) { |
| | | result[startRowDataIndex + 4 * i + 0] = 0; |
| | | result[startRowDataIndex + 4 * i + 1] = 0; |
| | |
| | | //排除第一列序号列 |
| | | int startRowDataIndex = (ELE_NUMBER_PER_LINE) * 4 * gid; |
| | | |
| | | for (int i = startCol;i <= endCol;i++) { |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | |
| | | bool empty = 1; |
| | | for (int j = startRow;j <= endRow;j++) { |
| | | for (int j = startRow; j <= endRow; j++) { |
| | | unsigned char value = imgs[get_one_level_position(width, i, j)]; |
| | | if (value >= 64) { |
| | | empty = 0; |
| | |
| | | } |
| | | |
| | | int emptyCount = 0; |
| | | for (int i = 0;i < ELE_NUMBER_PER_LINE;i++) { |
| | | for (int i = 0; i < ELE_NUMBER_PER_LINE; i++) { |
| | | result[startRowDataIndex + 4 * i + 0] = rowDataIndexs[4 * (i - emptyCount) + 0]; |
| | | result[startRowDataIndex + 4 * i + 1] = rowDataIndexs[4 * (i - emptyCount) + 1]; |
| | | result[startRowDataIndex + 4 * i + 2] = rowDataIndexs[4 * (i - emptyCount) + 2]; |
| | |
| | | |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | for (int c = 0; c < width; c++) { |
| | | int index = rowIndex * width + c; |
| | | int start = index * 3; |
| | | unsigned char R = imgs[start]; |
| | |
| | | |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | for (int c = 0; c < width; c++) { |
| | | int index = rowIndex * width + c; |
| | | int start = index * 3; |
| | | unsigned char R = imgs[start]; |
| | |
| | | |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | for (int c = 0; c < width; c++) { |
| | | int index = rowIndex * width + c; |
| | | int start = index * 4; |
| | | unsigned char R = imgs[start]; |
| | |
| | | |
| | | |
| | | __kernel void rgba2ThresholdInvert(const __global unsigned char* imgs, int width, |
| | | __global unsigned char* result,int threadhold) { |
| | | __global unsigned char* result, int threadhold) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | for (int c = 0; c < width; c++) { |
| | | int index = rowIndex * width + c; |
| | | int start = index * 4; |
| | | unsigned char R = imgs[start]; |
| | |
| | | int endy = startx + 3; |
| | | if (rowIndexs[startx] > 0) { |
| | | int emptyX = -1; |
| | | for (int x = rowIndexs[endx];x >= rowIndexs[startx];x--) |
| | | for (int x = rowIndexs[endx]; x >= rowIndexs[startx]; x--) |
| | | { |
| | | bool empty = true; |
| | | for (int y = rowIndexs[starty];y <= rowIndexs[endy];y++) { |
| | | for (int y = rowIndexs[starty]; y <= rowIndexs[endy]; y++) { |
| | | unsigned char value = imgs[get_one_level_position(width, x, y)]; |
| | | if (get_binary_value(value)) { |
| | | empty = 0; |
| | |
| | | if (emptyX > 0) { |
| | | //计算值 |
| | | unsigned char count = 0; |
| | | for (int x = emptyX + 1;x <= rowIndexs[endx];x++) |
| | | for (int x = emptyX + 1; x <= rowIndexs[endx]; x++) |
| | | { |
| | | for (int y = rowIndexs[starty];y <= rowIndexs[endy];y++) { |
| | | for (int y = rowIndexs[starty]; y <= rowIndexs[endy]; y++) { |
| | | unsigned char value = imgs[get_one_level_position(width, x, y)]; |
| | | count += get_binary_value(value) ? 1 : 0; |
| | | } |
| | |
| | | |
| | | result[row * 2] = 1; |
| | | //去除上下的空白 |
| | | for (int r = starty;r <= endy;r++) |
| | | for (int r = starty; r <= endy; r++) |
| | | { |
| | | bool empty = true; |
| | | for (int c = startx;c <= endx;c++) { |
| | | for (int c = startx; c <= endx; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | if (get_binary_value(value)) { |
| | | empty = 0; |
| | |
| | | break; |
| | | } |
| | | } |
| | | for (int r = endy;r >= starty;r--) |
| | | for (int r = endy; r >= starty; r--) |
| | | { |
| | | bool empty = true; |
| | | for (int c = startx;c <= endx;c++) { |
| | | for (int c = startx; c <= endx; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | if (get_binary_value(value)) { |
| | | empty = 0; |
| | |
| | | int my = (starty + endy) / 2; |
| | | //计算上半部分的值 |
| | | int topValue = 0; |
| | | for (int r = starty;r <= my;r++) |
| | | for (int r = starty; r <= my; r++) |
| | | { |
| | | for (int c = startx;c <= endx;c++) { |
| | | for (int c = startx; c <= endx; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | topValue += get_binary_value(value); |
| | | |
| | |
| | | } |
| | | //计算下半部分的值 |
| | | int bottomValue = 0; |
| | | for (int r = my;r <= endy;r++) |
| | | for (int r = my; r <= endy; r++) |
| | | { |
| | | for (int c = startx;c <= endx;c++) { |
| | | for (int c = startx; c <= endx; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | bottomValue += get_binary_value(value); |
| | | |
| | |
| | | //printf("%d: %d %d %d %d\n",row, startx, starty, endx, endy); |
| | | |
| | | unsigned int pixelCount = 0; |
| | | for (int r = starty;r <= endy;r++) |
| | | for (int r = starty; r <= endy; r++) |
| | | { |
| | | for (int c = startx;c <= endx;c++) { |
| | | for (int c = startx; c <= endx; c++) { |
| | | unsigned char val = imgs[get_one_level_position(width, c, r)]; |
| | | pixelCount += get_binary_value(val); |
| | | } |
| | |
| | | //查询是否有单位 |
| | | //获取是否有单位 |
| | | int last_empty_index = -1; |
| | | for (i = endx;i >= startx;i--) { |
| | | for (i = endx; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(imgs[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | return; |
| | | } |
| | | |
| | | for (i = endx - 11;i >= startx;i--) { |
| | | for (i = endx - 11; i >= startx; i--) { |
| | | bool empty = 1; |
| | | for (int y = starty;y < endy;y++) { |
| | | for (int y = starty; y < endy; y++) { |
| | | if (get_binary_value(imgs[get_one_level_position(width, i, y)]) > 0) { |
| | | empty = 0; |
| | | break; |
| | |
| | | int count = 0; |
| | | if (unit_start > -1) |
| | | { |
| | | for (int c = unit_start;c <= endx;c++) { |
| | | for (int y = starty;y <= endy;y++) { |
| | | for (int c = unit_start; c <= endx; c++) { |
| | | for (int y = starty; y <= endy; y++) { |
| | | count += (get_binary_value(imgs[get_one_level_position(width, c, y)]) > 0 ? 1 : 0); |
| | | } |
| | | } |