admin
2022-06-27 eda1a611bc4afcf1c36a6c728f432aec1f688e1b
ConsoleApplication/kernel.cl
@@ -1,45 +1,45 @@
#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) {
@@ -49,13 +49,8 @@
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);
@@ -355,15 +350,15 @@
   //开始填充数据
   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;
            }
         }
@@ -372,44 +367,44 @@
         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];
            }
         }
      }
@@ -422,30 +417,30 @@
__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);
            }