Commit c88c297f40f0715c16b53749e743ef931acec9dc
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,23 +164,30 @@ Mat BEE::readMat(const br::File &matrix, QString *targetSigset, QString *querySi | ||
| 164 | int typeSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t); | 164 | int typeSize = isMask ? sizeof(BEE::Mask_t) : sizeof(BEE::Simmat_t); |
| 165 | 165 | ||
| 166 | // Get matrix data | 166 | // Get matrix data |
| 167 | - qint64 bytesExpected = (qint64)rows*(qint64)cols*(qint64)typeSize; | ||
| 168 | Mat m; | 167 | Mat m; |
| 169 | if (isMask) | 168 | if (isMask) |
| 170 | m.create(rows, cols, OpenCVType<BEE::Mask_t,1>::make()); | 169 | m.create(rows, cols, OpenCVType<BEE::Mask_t,1>::make()); |
| 171 | else | 170 | else |
| 172 | m.create(rows, cols, OpenCVType<BEE::Simmat_t,1>::make()); | 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 | if (!file.atEnd()) | 184 | if (!file.atEnd()) |
| 178 | qFatal("Expected matrix end of file."); | 185 | qFatal("Expected matrix end of file."); |
| 179 | file.close(); | 186 | file.close(); |
| 180 | 187 | ||
| 181 | - Mat result; | 188 | + Mat result = m; |
| 182 | if (isDistance ^ matrix.get<bool>("negate", false)) m.convertTo(result, -1, -1); | 189 | if (isDistance ^ matrix.get<bool>("negate", false)) m.convertTo(result, -1, -1); |
| 183 | - else result = m.clone(); | 190 | + |
| 184 | return result; | 191 | return result; |
| 185 | } | 192 | } |
| 186 | 193 |