Exemple #1
0
QVector<ProfileItem> CardOCR::scanLeftProfile(const BoolMatrix & imgMatrix)
{
   //дальше сравнене по профилям
   //сканирование левого профиля
   const int w = imgMatrix.width();
   const int h = imgMatrix.height();
   int min_x = w, max_x = 0;

   QVector<int> x_array;
   for (int y = 0; y < h; ++y)
   {
      for (int x = 0; x < w; ++x)
      {
         if (imgMatrix.at(x, y) == 1)
         {
            if (x < min_x)
               min_x = x;
            if (x > max_x)
               max_x = x;
            x_array.push_back(x);
            break;
         }
      }
   }
   
   //определяем середину
   int x_border = min_x + (max_x - min_x) / 2;
   //формируем портрет профиля
   QVector<bool> prof;
   QVector<ProfileItem> profile;

   //qDebug() << x_array;
   int ccnt = 0;
   bool item = true;
   foreach (int x, x_array)
   {
      item = (x > x_border);
      if (prof.size() == 0)
      {
         prof.push_back(item);
         ccnt++;
      }
      else
      {
         if (prof.last() != item)
         {
            ProfileItem it;
            it.item = !item;
            it.value = qreal(ccnt) / qreal(h);
            profile.push_back(it);
            prof.push_back(item);
            ccnt = 1;
         }
         else
         {
            ccnt++;
         }
      }
   }
Exemple #2
0
//@+node:gcross.20101224191604.2770: ** Functions
//@+node:gcross.20110114154616.2017: *3* channelMatrix
IntMatrix channelMatrix(Space& space, const BoolMatrix& matrix) {
    BoolVarArgs vars = matrix.get_array();
    IntVarArgs vars_as_ints(space,vars.size(),0,1);
    BOOST_FOREACH(const unsigned int i, irange(0u,(unsigned int)vars.size())) { channel(space,vars[i],vars_as_ints[i]); }
    return IntMatrix(vars_as_ints,matrix.width(),matrix.height());
}