From a17738e1545ff7dbef6398b8ec1eab93ab59c9a1 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 30 六月 2022 19:14:47 +0800 Subject: [PATCH] '功能完善' --- ConsoleApplication/kernel.cl | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 160 insertions(+), 13 deletions(-) diff --git a/ConsoleApplication/kernel.cl b/ConsoleApplication/kernel.cl index 28b9174..9ab5447 100644 --- a/ConsoleApplication/kernel.cl +++ b/ConsoleApplication/kernel.cl @@ -1,10 +1,10 @@ __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 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 * num_width * num_height + p % (num_count*10) * num_width; + 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++) { @@ -26,7 +26,7 @@ int endIndex = (index + 1) * 10; //获取最小值 - int min =255; + int min = 255; int minIndex = 11; for (int i = startIndex;i < endIndex;i++) @@ -50,7 +50,7 @@ return v >= 64 ? 1 : 0; } -__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, +__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); @@ -350,7 +350,7 @@ //开始填充数据 for (i = 0;i < maxNumberCount;i++) { - unsigned char numData[100*100]; + unsigned char numData[100 * 100]; if (fresult[i * 2] == -1) { //填充0 @@ -358,7 +358,7 @@ 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; + numData[r * num_width + c] = value; } } @@ -373,10 +373,10 @@ //填充空白0 value = get_binary_value(img_in[get_one_level_position(width, _startx + c, r)]); //设置输出坐标的值 - numData[(r - starty)* num_width+c] = value; + numData[(r - starty) * num_width + c] = value; } else { - numData[(r - starty)* num_width+c] = 0; + numData[(r - starty) * num_width + c] = 0; } } } @@ -404,7 +404,7 @@ 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]; + result[findex] = numData[r * num_width + c]; } } } @@ -417,7 +417,7 @@ -__kernel void createTemplateNumbers(__global unsigned char* numbers,int num_width,int num_height, 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); @@ -587,16 +587,163 @@ __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; + } } \ No newline at end of file -- Gitblit v1.8.0