Commit c88c297f40f0715c16b53749e743ef931acec9dc

Authored by Charles Otto
1 parent c407dd5f

Read bee format galleries row by row instead of as a single blob

For sufficiently large matrices, reading as a single blob will fail
Showing 1 changed file with 13 additions and 6 deletions
openbr/core/bee.cpp
... ... @@ -164,23 +164,30 @@ Mat BEE::readMat(const br::File &matrix, QString *targetSigset, QString *querySi
164 164 int typeSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t);
165 165  
166 166 // Get matrix data
167   - qint64 bytesExpected = (qint64)rows*(qint64)cols*(qint64)typeSize;
168 167 Mat m;
169 168 if (isMask)
170 169 m.create(rows, cols, OpenCVType<BEE::Mask_t,1>::make());
171 170 else
172 171 m.create(rows, cols, OpenCVType<BEE::Simmat_t,1>::make());
173 172  
174   - qint64 read = file.read((char*)m.data, bytesExpected);
175   - if (read != bytesExpected)
176   - qFatal("Invalid matrix size.");
  173 + qint64 bytesPerRow = m.cols * typeSize;
  174 +
  175 + for (int i=0; i < m.rows;i++)
  176 + {
  177 + cv::Mat aRow = m.row(i);
  178 + qint64 bytesRead = file.read((char *)aRow.data, bytesPerRow);
  179 + if (bytesRead != bytesPerRow)
  180 + {
  181 + qFatal("Didn't read complete row!");
  182 + }
  183 + }
177 184 if (!file.atEnd())
178 185 qFatal("Expected matrix end of file.");
179 186 file.close();
180 187  
181   - Mat result;
  188 + Mat result = m;
182 189 if (isDistance ^ matrix.get<bool>("negate", false)) m.convertTo(result, -1, -1);
183   - else result = m.clone();
  190 +
184 191 return result;
185 192 }
186 193  
... ...