| | |
| | | |
| | | #define ROWS 8 |
| | | #define COLS 5 |
| | | |
| | | __kernel void createBuffer(__global const float* a_in, |
| | | __global const float* b_in, |
| | | __global float* result) { |
| | | int gid = get_global_id(0); |
| | | result[gid] = a_in[gid] * b_in[gid]; |
| | | } |
| | | |
| | | __kernel void test1(__global const unsigned char* a_in, |
| | | __global const unsigned char* b_in, int width, |
| | | __kernel void recognition_numbers_1(__global const unsigned char* a_in, |
| | | __global const unsigned char* b_in, int width, int num_width, int num_height, int num_count, |
| | | __global unsigned char* result) { |
| | | |
| | | int p = get_global_id(0); |
| | | int startIndex = p / width * width * 5 * 8 + p % 170 * 5; |
| | | int startIndex = p / width * width * num_width * num_height + p % (num_count * 10) * num_width; |
| | | unsigned char t = 0; |
| | | for (int r = 0;r < 8;r++) |
| | | for (int c = 0;c < 5;c++) { |
| | | int index = startIndex + 5 * width * r + c; |
| | | t += (a_in[index] ^ b_in[index]); |
| | | 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) { |
| | | //printf("ֵ:%d-%d \n", a_in[index], b_in[index]); |
| | | } |
| | | } |
| | | result[p] = t; |
| | | } |
| | | |
| | | |
| | | __kernel void test2(__global const unsigned char* a_in, |
| | | __kernel void recognition_numbers_2(__global const unsigned char* a_in, |
| | | __global unsigned char* result) { |
| | | |
| | | int index = get_global_id(0); |
| | | int startIndex = index * 10; |
| | | int endIndex = (index + 1) * 10; |
| | | |
| | | //获取最小值 |
| | | int min = 255; |
| | | int minIndex = 11; |
| | | |
| | | for (int i = startIndex;i < endIndex;i++) |
| | | { |
| | | if (a_in[i] == 0) { |
| | | result[index] = i - startIndex; |
| | | break; |
| | | if (a_in[i] < min) { |
| | | min = a_in[i]; |
| | | minIndex = i; |
| | | } |
| | | } |
| | | |
| | | //printf("最小值:%d - %d - %d \n", index, min, minIndex - startIndex); |
| | | |
| | | result[index] = minIndex - startIndex; |
| | | } |
| | | |
| | | int get_one_level_position(int width, int x, int y) { |
| | |
| | | unsigned char get_binary_value(unsigned char v) { |
| | | return v >= 64 ? 1 : 0; |
| | | } |
| | | __kernel void test5(__global const unsigned char* img_in, __global const int* pos_in, __global const unsigned char* zero, int width, |
| | | __global unsigned char* result) { |
| | | |
| | | } |
| | | |
| | | |
| | | __kernel void test4(__global const unsigned char* img_in, __global const int* pos_in, __global const unsigned char* zero, int width, |
| | | __kernel void split_num(__global const unsigned char* img_in, __global const int* pos_in, __global const unsigned char* zero, int width, int num_width, int num_height, int num_count, |
| | | __global unsigned char* result) { |
| | | |
| | | int index = get_global_id(0); |
| | |
| | | //开始填充数据 |
| | | for (i = 0;i < maxNumberCount;i++) { |
| | | |
| | | unsigned char numData[8][5]; |
| | | unsigned char numData[100 * 100]; |
| | | |
| | | if (fresult[i * 2] == -1) { |
| | | //填充0 |
| | | for (int r = 0;r < 8;r++) { |
| | | for (int c = 0;c < 5;c++) { |
| | | unsigned char value = get_binary_value(zero[r * 5 + 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][c] = value; |
| | | numData[r * num_width + c] = value; |
| | | } |
| | | } |
| | | |
| | |
| | | int _startx = fresult[i * 2]; |
| | | int _endx = fresult[i * 2 + 1]; |
| | | for (int r = starty;r <= endy;r++) { |
| | | for (int c = 0;c < 5;c++) { |
| | | for (int c = 0;c < num_width;c++) { |
| | | unsigned char value = 0; |
| | | if (_startx + c <= _endx) { |
| | | //填充空白0 |
| | | value = get_binary_value(img_in[get_one_level_position(width, _startx + c, r)]); |
| | | //设置输出坐标的值 |
| | | numData[r - starty][c] = value; |
| | | numData[(r - starty) * num_width + c] = value; |
| | | } |
| | | else { |
| | | numData[r - starty][c] = 0; |
| | | numData[(r - starty) * num_width + c] = 0; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | int rowData = ROWS * COLS * 10 * 17; |
| | | int rowData = num_height * num_width * 10 * num_count; |
| | | int rowIndex = index / 3; |
| | | int index_0 = rowData * rowIndex; |
| | | //设置坐标值 |
| | | int index_2 = 0; |
| | | if (index % 3 == 0) { |
| | | index_2 += COLS * 10 * i; |
| | | index_2 += num_width * 10 * i; |
| | | } |
| | | else if (index % 3 == 1) { |
| | | index_2 += (COLS * 10) * (6 + i); |
| | | index_2 += (num_width * 10) * (6 + i); |
| | | } |
| | | else { |
| | | index_2 += (COLS * 10) * (6 + 6 + i); |
| | | index_2 += (num_width * 10) * (6 + 6 + i); |
| | | } |
| | | |
| | | for (int re = 0;re < 10;re++) { |
| | | int index_3 = re * COLS; |
| | | for (int r = 0;r < 8;r++) { |
| | | int index_1 = r * (COLS * 10 * 17); |
| | | for (int c = 0;c < COLS;c++) { |
| | | int index_3 = re * num_width; |
| | | 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++) { |
| | | int findex = index_0 + index_1 + index_2 + index_3 + c; |
| | | //printf("index:%d-findex:%d \n",index, findex); |
| | | result[findex] = numData[r][c]; |
| | | result[findex] = numData[r * num_width + c]; |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | |
| | | __kernel void createTemplateNumbers(__global unsigned char* numbers, int countPerLine, |
| | | __kernel void createTemplateNumbers(__global unsigned char* numbers, int num_width, int num_height, int countPerLine, |
| | | __global unsigned char* result) { |
| | | |
| | | int gid = get_global_id(0); |
| | | int LINE_NUMBER_COUNT = countPerLine; |
| | | int NUMBER_COUNT = 10; |
| | | //unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * (ROWS * lines) *COLS * NUMBER_COUNT * LINE_NUMBER_COUNT); |
| | | int outLineDataCount = ROWS * COLS * NUMBER_COUNT * LINE_NUMBER_COUNT; |
| | | int inLineDataCount = COLS * NUMBER_COUNT * LINE_NUMBER_COUNT; |
| | | int outLineDataCount = num_height * num_width * NUMBER_COUNT * LINE_NUMBER_COUNT; |
| | | 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++) |
| | | { |
| | | int index_num_0 = n * ROWS * COLS; |
| | | for (int r = 0;r < ROWS;r++) { |
| | | int index_num_0 = n * num_width * num_height; |
| | | for (int r = 0;r < num_height;r++) { |
| | | int intLineCount = inLineDataCount * r; |
| | | |
| | | for (int c = 0;c < COLS;c++) { |
| | | int index_num = index_num_0 + r * COLS + 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; |
| | | index += intLineCount; |
| | | int x = re * NUMBER_COUNT * COLS + n * COLS + c; |
| | | int x = re * NUMBER_COUNT * num_width + n * num_width + c; |
| | | index += x; |
| | | result[index] = get_binary_value(value); |
| | | } |
| | |
| | | __kernel void rgb2GrayImg(__global unsigned char* imgs, int width, |
| | | __global unsigned char* result) { |
| | | |
| | | int rowIndex= get_global_id(0); |
| | | int rowIndex = get_global_id(0); |
| | | |
| | | for (int c = 0;c < width;c++) { |
| | | 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; |
| | | } |
| | | |
| | | } |