| | |
| | | nps[1] = starty; |
| | | nps[2] = emptyX - 1; |
| | | nps[3] = endy; |
| | | //去除上下的空白,防止h单位出现问题 |
| | | //去除上下的白边 |
| | | int y = 0; |
| | | for (y = nps[1]; y <= nps[3]; y++) { |
| | | bool empty = 1; |
| | | for (int x = nps[0]; x <= nps[2]; 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) { |
| | | nps[1] = y; |
| | | starty = y; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (y = nps[3]; y >= nps[1]; y--) { |
| | | bool empty = 1; |
| | | for (int x = nps[0]; x <= nps[2]; 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) { |
| | | nps[3] = y; |
| | | endy = y; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | //printf("撤单时间未解析到分隔符:%d", index); |
| | |
| | | emptyEnd = i; |
| | | } |
| | | |
| | | int SPACE = 5; |
| | | //时间的宽度为45-47 |
| | | if (rowDataSize == 0 && (dataEnd - dataStart + 1 >= 45)) { |
| | | SPACE = 1; |
| | | } |
| | | |
| | | //3个及以上的空白数据才分列 |
| | | if (emptyEnd - emptyStart >= 5 && dataEnd - dataStart > 0) { |
| | | if (emptyEnd - emptyStart >= SPACE && dataEnd - dataStart > 0) { |
| | | |
| | | rowDataIndexs[rowDataSize * 4 + 0] = dataStart; |
| | | rowDataIndexs[rowDataSize * 4 + 1] = startRow; |
| | |
| | | } |
| | | |
| | | |
| | | int int_sort(int arr[], int len,int ele_count,int index) |
| | | { |
| | | int j, k; //定义循环因子,嵌套双层循环 |
| | | for (j = 0; j < len - 1; j++) //设置循环后界 |
| | | { |
| | | for (k = 0; k < len - j - 1; k++) //不断向后进行比较 |
| | | { |
| | | if (arr[k] < arr[k + 1]) //比较相邻的元素 |
| | | { |
| | | int temp = arr[k]; //三杯水交换法 |
| | | arr[k] = arr[k + 1]; |
| | | arr[k + 1] = temp; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //if (index == 136) { |
| | | // for (j = 0; j < len; j++) { |
| | | // printf("%d,", arr[j]); |
| | | // } |
| | | //} |
| | | |
| | | if (ele_count > len) { |
| | | return arr[len - 1]; |
| | | } |
| | | else |
| | | { |
| | | return arr[ele_count - 2]; |
| | | } |
| | | } |
| | | |
| | | //切分行数据 |
| | | //width:图像宽度 |
| | | //ele_count:每一行的元素数量 |
| | | //min_empty_width:最小空白,小于这个值不算空白 |
| | | //threshhold_color:小于这个值表示无内容,反之表示有内容 |
| | | __kernel void splitRowData(__global unsigned char* imgs, __global int* rowIndexs, int width,int ele_count,int min_empty_width,int threshhold_color, |
| | | __global int* result) { |
| | | int gid = get_global_id(0); |
| | | |
| | | int startCol = rowIndexs[gid * 4]; |
| | | int startRow = rowIndexs[gid * 4 + 1]; |
| | | int endCol = rowIndexs[gid * 4 + 2]; |
| | | int endRow = rowIndexs[gid * 4 + 3]; |
| | | |
| | | //printf(" index:%d - startCol:%d,startRow:%d,endCol:%d,endRow:%d\n", gid, startCol, startRow, endCol, endRow); |
| | | |
| | | |
| | | int emptyStart = -1; |
| | | int emptyEnd = -1; |
| | | int dataStart = -1; |
| | | int dataEnd = -1; |
| | | |
| | | int rowDataSize = 0; |
| | | // 最大兼容20个数据 |
| | | int rowDataIndexs[20 * 4]; |
| | | //最大兼容80个数据 |
| | | int startRowDataIndex = ele_count * 4 * gid; |
| | | int empty_area_width[80]; |
| | | |
| | | //统计空白的宽度 |
| | | int empty_index = 0; |
| | | bool is_start = 0; |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | bool empty = 1; |
| | | for (int j = startRow; j <= endRow; j++) { |
| | | unsigned char value = imgs[get_one_level_position(width, i, j)]; |
| | | if (value >= threshhold_color) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | if (emptyStart < 0) { |
| | | emptyStart = i; |
| | | emptyEnd = i; |
| | | } |
| | | else { |
| | | emptyEnd = i; |
| | | } |
| | | } |
| | | else { |
| | | if (emptyEnd - emptyStart >= min_empty_width && is_start) { |
| | | //if (gid == 136) { |
| | | // printf("%d,%d,%d,%d\n", emptyStart, startRow, emptyEnd, endRow); |
| | | //} |
| | | empty_area_width[empty_index] = emptyEnd - emptyStart + 1; |
| | | empty_index++; |
| | | } |
| | | emptyEnd = -1; |
| | | emptyStart = -1; |
| | | is_start = 1; |
| | | |
| | | } |
| | | } |
| | | //求前ele_count-1的空白宽度 |
| | | int empty_width = int_sort(empty_area_width, empty_index,ele_count, gid); |
| | | |
| | | |
| | | |
| | | emptyStart = -1; |
| | | emptyEnd = -1; |
| | | dataStart = -1; |
| | | dataEnd = -1; |
| | | |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | |
| | | bool empty = 1; |
| | | for (int j = startRow; j <= endRow; j++) { |
| | | unsigned char value = imgs[get_one_level_position(width, i, j)]; |
| | | if (value >= threshhold_color) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (empty) { |
| | | if (emptyStart < 0) { |
| | | emptyStart = i; |
| | | emptyEnd = i; |
| | | } |
| | | else { |
| | | emptyEnd = i; |
| | | } |
| | | |
| | | //3个及以上的空白数据才分列 |
| | | if (emptyEnd - emptyStart + 1 >= empty_width && dataEnd - dataStart > 0) { |
| | | rowDataIndexs[rowDataSize * 4 + 0] = dataStart; |
| | | rowDataIndexs[rowDataSize * 4 + 1] = startRow; |
| | | rowDataIndexs[rowDataSize * 4 + 2] = dataEnd; |
| | | rowDataIndexs[rowDataSize * 4 + 3] = endRow; |
| | | rowDataSize++; |
| | | dataEnd = -1; |
| | | dataStart = -1; |
| | | } |
| | | } |
| | | else { |
| | | if (dataStart < 0) { |
| | | dataStart = i; |
| | | dataEnd = i; |
| | | } |
| | | else { |
| | | dataEnd = i; |
| | | } |
| | | |
| | | emptyStart = -1; |
| | | emptyEnd = -1; |
| | | } |
| | | } |
| | | //后面的数据没有足够的空白分隔 |
| | | if (dataEnd - dataStart > 0) { |
| | | rowDataIndexs[rowDataSize * 4 + 0] = dataStart; |
| | | rowDataIndexs[rowDataSize * 4 + 1] = startRow; |
| | | rowDataIndexs[rowDataSize * 4 + 2] = dataEnd; |
| | | rowDataIndexs[rowDataSize * 4 + 3] = endRow; |
| | | rowDataSize++; |
| | | } |
| | | //if (rowDataSize > 4) |
| | | //{ |
| | | // printf("data_size:%d %d %d\n", gid, rowDataSize, empty_width); |
| | | //} |
| | | //去除上下空白 |
| | | for (int i = 0; i < rowDataSize; i++) { |
| | | int start_x = rowDataIndexs[i * 4 + 0]; |
| | | int start_y = rowDataIndexs[i * 4 + 1]; |
| | | int end_x = rowDataIndexs[i * 4 + 2]; |
| | | int end_y = rowDataIndexs[i * 4 + 3]; |
| | | //去除上空白 |
| | | for (int r = start_y; r <= end_y; r++) { |
| | | bool empty = 1; |
| | | for (int c = start_x; c <= end_x; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | if (value >= threshhold_color) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty){ |
| | | start_y = r; |
| | | break; |
| | | } |
| | | } |
| | | rowDataIndexs[i * 4 + 1] = start_y; |
| | | |
| | | //去除下空白 |
| | | for (int r = end_y; r >= start_y; r--) { |
| | | bool empty = 1; |
| | | for (int c = start_x; c <= end_x; c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | if (value >= threshhold_color) { |
| | | empty = 0; |
| | | break; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | end_y = r; |
| | | break; |
| | | } |
| | | } |
| | | rowDataIndexs[i * 4 + 3] = end_y; |
| | | } |
| | | |
| | | |
| | | |
| | | int emptyColIndex1 = -1; |
| | | int emptyColIndex2 = -1; |
| | | int emptyCount = 0; |
| | | for (int i = 0; i < ele_count; i++) { |
| | | if (i == emptyColIndex1 || i == emptyColIndex2) { |
| | | result[startRowDataIndex + 4 * i + 0] = 0; |
| | | result[startRowDataIndex + 4 * i + 1] = 0; |
| | | result[startRowDataIndex + 4 * i + 2] = 0; |
| | | result[startRowDataIndex + 4 * i + 3] = 0; |
| | | emptyCount++; |
| | | } |
| | | else { |
| | | 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]; |
| | | result[startRowDataIndex + 4 * i + 3] = rowDataIndexs[4 * (i - emptyCount) + 3]; |
| | | /* |
| | | if(gid==0) |
| | | |
| | | printf("%d-%d: %d %d %d %d \n", startRowDataIndex + 4 * i + 0,i, rowDataIndexs[4 * (i - emptyCount) + 0], rowDataIndexs[4 * (i - emptyCount) + 1], rowDataIndexs[4 * (i - emptyCount) + 2], rowDataIndexs[4 * (i - emptyCount) + 3]); |
| | | */ |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | __kernel void splitCommonRowData(__global unsigned char* imgs, __global int* rowIndexs, int width, int fromIndex, int toIndex, |
| | | __global int* result) { |