| | |
| | | int index = rowIndex * width + c; |
| | | int start = index * 3; |
| | | unsigned char R = imgs[start]; |
| | | unsigned G = imgs[start + 1]; |
| | | unsigned B = imgs[start + 2]; |
| | | unsigned char G = imgs[start + 1]; |
| | | unsigned char B = imgs[start + 2]; |
| | | result[index] = (76 * R + 150 * G + 30 * B) >> 8; |
| | | } |
| | | } |
| | | |
| | | __kernel void rgba2GrayImg(__global unsigned char* imgs, int width, |
| | | __global unsigned char* result) { |
| | | |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | int index = rowIndex * width + c; |
| | | int start = index * 4; |
| | | unsigned char R = imgs[start]; |
| | | unsigned char G = imgs[start + 1]; |
| | | unsigned char B = imgs[start + 2]; |
| | | result[index] = (76 * R + 150 * G + 30 * B) >> 8; |
| | | } |
| | | } |
| | | |
| | | |
| | | //L2非数字识别 |
| | | __kernel void recognition_not_num(__global unsigned char* imgs, __global int* rowIndexs, int width, |
| | | __global int* result) { |
| | | |
| | | int index = get_global_id(0); |
| | | int row = index / 2; |
| | | int baseIndex = row * 4 * 7; |
| | | if (index % 2 == 0) { |
| | | //涨跌停价 |
| | | //获取数据坐标 |
| | | int startx = baseIndex + 3 * 4; |
| | | int starty = startx + 1; |
| | | int endx = startx + 2; |
| | | int endy = startx + 3; |
| | | if (rowIndexs[startx] <= 0 && rowIndexs[starty] <= 0 && rowIndexs[endx] <= 0 && rowIndexs[endy] <= 0) { |
| | | result[row * 2] = 0; |
| | | } |
| | | else { |
| | | startx = rowIndexs[startx]; |
| | | starty = rowIndexs[starty]; |
| | | endx = rowIndexs[endx]; |
| | | endy = rowIndexs[endy]; |
| | | |
| | | result[row * 2] = 1; |
| | | //去除上下的空白 |
| | | for (int r = starty;r <= endy;r++) |
| | | { |
| | | bool empty = true; |
| | | 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; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | starty = r; |
| | | break; |
| | | } |
| | | } |
| | | for (int r = endy;r >= starty;r--) |
| | | { |
| | | bool empty = true; |
| | | 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; |
| | | } |
| | | } |
| | | if (!empty) { |
| | | endy = r; |
| | | break; |
| | | } |
| | | } |
| | | int my = (starty + endy) / 2; |
| | | //计算上半部分的值 |
| | | int topValue = 0; |
| | | for (int r = starty;r <= my;r++) |
| | | { |
| | | 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 c = startx;c <= endx;c++) { |
| | | unsigned char value = imgs[get_one_level_position(width, c, r)]; |
| | | bottomValue += get_binary_value(value); |
| | | |
| | | } |
| | | } |
| | | |
| | | if (topValue > bottomValue) { |
| | | //涨停 |
| | | result[row * 2] = 1; |
| | | } |
| | | else { |
| | | //跌停 |
| | | result[row * 2] = 2; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | //操作类型 |
| | | //计算值 |
| | | int startx = baseIndex + 6 * 4; |
| | | int starty = startx + 1; |
| | | int endx = startx + 2; |
| | | int endy = startx + 3; |
| | | startx = rowIndexs[startx]; |
| | | starty = rowIndexs[starty]; |
| | | endx = rowIndexs[endx]; |
| | | endy = rowIndexs[endy]; |
| | | |
| | | //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 c = startx;c <= endx;c++) { |
| | | unsigned char val = imgs[get_one_level_position(width, c, r)]; |
| | | pixelCount+=get_binary_value(val); |
| | | } |
| | | } |
| | | |
| | | //初始化错误复制 |
| | | int value = 4; |
| | | if (abs(pixelCount - 39) < 5) { |
| | | //买 |
| | | value = 0; |
| | | } |
| | | else if (abs(pixelCount - 51) < 5) { |
| | | //卖 |
| | | value = 2; |
| | | } |
| | | else if (abs(pixelCount - 105) < 5) { |
| | | //买撤 |
| | | value = 1; |
| | | } |
| | | else if (abs(pixelCount - 117) < 5) { |
| | | //卖撤 |
| | | value = 3; |
| | | } |
| | | result[row * 2 + 1] = value; |
| | | } |
| | | |
| | | } |