admin
2022-09-09 60feedf43a35a9ca69d05095a01c5d1797b1bdc3
ConsoleApplication/kernel.cl
@@ -452,8 +452,133 @@
      nps[10] = -1;
      nps[11] = -1;
   }
   //百分比
   else if (type == 5) {
      //百分比数字起始位置
      int percent_start = -1;
      int emptyIndex = -1;
      int i;
      for (i = startx;i <= endx;i++) {
         bool empty = 1;
         for (int y = starty;y < endy;y++) {
            if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) {
               empty = 0;
               break;
            }
         }
         if (empty) {
            emptyIndex = i;
         }else if (emptyIndex > 0) {
            percent_start = i;
            break;
         }
      }
      //百分比数字的结束位置
      int percent_end = -1;
      emptyIndex = -1;
      for (i = endx;i >= startx;i--) {
         bool empty = 1;
         for (int y = starty;y < endy;y++) {
            if (get_binary_value(img_in[get_one_level_position(width, i, y)]) > 0) {
               empty = 0;
               break;
            }
         }
         if (empty) {
            emptyIndex = i;
         }else if (emptyIndex > 0) {
            percent_end = i;
            break;
         }
      }
      if (percent_start > -1) {
         startx = percent_start;
      }
      if (percent_end > -1) {
         endx = percent_end;
      }
      //按照价格的形式做识别
      int m_s = -1, m_e = -1;
      uchar temp[8];
      for (i = 0;i < cols;i++) {
         if (i > cols - 5) {
            break;
         }
         temp[0] = get_binary_value(img_in[get_one_level_position(width, startx + i, endy)]);
         temp[1] = get_binary_value(img_in[get_one_level_position(width, startx + i + 1, endy)]);
         temp[2] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy)]);
         temp[3] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy)]);
         temp[4] = get_binary_value(img_in[get_one_level_position(width, startx + i + 4, endy)]);
         temp[5] = get_binary_value(img_in[get_one_level_position(width, startx + i + 5, endy)]);
         temp[6] = get_binary_value(img_in[get_one_level_position(width, startx + i + 2, endy - 1)]);
         temp[7] = get_binary_value(img_in[get_one_level_position(width, startx + i + 3, endy - 1)]);
         if (temp[2] > 0 && temp[3] > 0 && temp[6] > 0 && temp[7] > 0) {
            if (temp[0] + temp[1] + temp[4] + temp[5] == 0)
            {
               bool empty = 1;
               for (int y = starty;y < endy - 1;y++) {
                  if (get_binary_value(img_in[get_one_level_position(width, startx + i + 2, y)]) > 0) {
                     empty = 0;
                     break;
                  }
               }
               //小数点上方为空值
               if (empty) {
                  m_s = i;
                  m_e = i + 5;
                  break;
               }
            }
         }
      }
      if (m_s == -1 || m_e == -1) {
         nps[0] = -1;
         nps[1] = -1;
         nps[2] = -1;
         nps[3] = -1;
         nps[4] = -1;
         nps[5] = -1;
         nps[6] = -1;
         nps[7] = -1;
      }
      else {
         nps[0] = startx;
         nps[1] = starty;
         nps[2] = startx + m_s - 1;
         nps[3] = endy;
         nps[4] = startx + m_e + 1;
         nps[5] = starty;
         nps[6] = endx;
         nps[7] = endy;
      }
      nps[8] = -1;
      nps[9] = -1;
      nps[10] = -1;
      nps[11] = -1;
   }
   //分隔数据
   //最大分割20个数
   int numCount = 0;
   //记录分割得到的数据