Commit 816a598ddff44fb3ce3428ac1fad63c0e2b1cdad
1 parent
9279f0b4
cleaned up whitespace, better errors to matrix (de)serialization
Showing
2 changed files
with
14 additions
and
48 deletions
openbr/core/opencvutils.cpp
| ... | ... | @@ -345,12 +345,12 @@ QDataStream &operator<<(QDataStream &stream, const Mat &m) |
| 345 | 345 | stream << rows << cols << type; |
| 346 | 346 | |
| 347 | 347 | // Write data |
| 348 | - int len = rows*cols*m.elemSize(); | |
| 348 | + int len = rows * cols * m.elemSize(); | |
| 349 | 349 | stream << len; |
| 350 | 350 | if (len > 0) { |
| 351 | 351 | if (!m.isContinuous()) qFatal("Can't serialize non-continuous matrices."); |
| 352 | 352 | int written = stream.writeRawData((const char*)m.data, len); |
| 353 | - if (written != len) qFatal("Serialization failure."); | |
| 353 | + if (written != len) qFatal("Mat serialization failure, expected: %d bytes, wrote: %d bytes.", len, written); | |
| 354 | 354 | } |
| 355 | 355 | return stream; |
| 356 | 356 | } |
| ... | ... | @@ -366,9 +366,9 @@ QDataStream &operator>>(QDataStream &stream, Mat &m) |
| 366 | 366 | int len; |
| 367 | 367 | stream >> len; |
| 368 | 368 | if (len > 0) { |
| 369 | - if (!m.isContinuous()) qFatal("opencvutils.cpp operator>> Mat can't deserialize non-continuous matrices."); | |
| 370 | - int written = stream.readRawData((char*)m.data, len); | |
| 371 | - if (written != len) qFatal("opencvutils.cpp operator>> Mat serialization failure."); | |
| 369 | + if (!m.isContinuous()) qFatal("Can't deserialize non-continuous matrices."); | |
| 370 | + const int read = stream.readRawData((char*)m.data, len); | |
| 371 | + if (read != len) qFatal("Mat deserialization failure, exptected: %d bytes, read: %d bytes.", len, read); | |
| 372 | 372 | } |
| 373 | 373 | return stream; |
| 374 | 374 | } | ... | ... |
openbr/core/opencvutils.h
| ... | ... | @@ -105,7 +105,6 @@ QDataStream &operator>>(QDataStream &stream, cv::Rect &r); |
| 105 | 105 | QDataStream &operator<<(QDataStream &stream, const cv::Size &s); |
| 106 | 106 | QDataStream &operator>>(QDataStream &stream, cv::Size &s); |
| 107 | 107 | |
| 108 | - | |
| 109 | 108 | // As described in "Modern C++ Design" Section 2.5. |
| 110 | 109 | template <typename T> |
| 111 | 110 | struct Type2Type |
| ... | ... | @@ -113,53 +112,20 @@ struct Type2Type |
| 113 | 112 | typedef T OriginalType; |
| 114 | 113 | }; |
| 115 | 114 | |
| 116 | -/**** | |
| 117 | -OpenCVType | |
| 118 | - Templated OpenCV Mat::type creation. | |
| 119 | -****/ | |
| 115 | +// Templated OpenCV Mat::type creation. | |
| 120 | 116 | template <typename Depth, int Channels> |
| 121 | 117 | class OpenCVType |
| 122 | 118 | { |
| 123 | - static int getDepth(Type2Type<uchar>) | |
| 124 | - { | |
| 125 | - return CV_8U; | |
| 126 | - } | |
| 127 | - | |
| 128 | - static int getDepth(Type2Type<char>) | |
| 129 | - { | |
| 130 | - return CV_8S; | |
| 131 | - } | |
| 132 | - | |
| 133 | - static int getDepth(Type2Type<ushort>) | |
| 134 | - { | |
| 135 | - return CV_16U; | |
| 136 | - } | |
| 137 | - | |
| 138 | - static int getDepth(Type2Type<short>) | |
| 139 | - { | |
| 140 | - return CV_16S; | |
| 141 | - } | |
| 142 | - | |
| 143 | - static int getDepth(Type2Type<long>) | |
| 144 | - { | |
| 145 | - return CV_32S; | |
| 146 | - } | |
| 147 | - | |
| 148 | - static int getDepth(Type2Type<float>) | |
| 149 | - { | |
| 150 | - return CV_32F; | |
| 151 | - } | |
| 152 | - | |
| 153 | - static int getDepth(Type2Type<double>) | |
| 154 | - { | |
| 155 | - return CV_64F; | |
| 156 | - } | |
| 119 | + static int getDepth(Type2Type<uchar>) { return CV_8U; } | |
| 120 | + static int getDepth(Type2Type<char>) { return CV_8S; } | |
| 121 | + static int getDepth(Type2Type<ushort>) { return CV_16U; } | |
| 122 | + static int getDepth(Type2Type<short>) { return CV_16S; } | |
| 123 | + static int getDepth(Type2Type<long>) { return CV_32S; } | |
| 124 | + static int getDepth(Type2Type<float>) { return CV_32F; } | |
| 125 | + static int getDepth(Type2Type<double>) { return CV_64F; } | |
| 157 | 126 | |
| 158 | 127 | public: |
| 159 | - static int make() | |
| 160 | - { | |
| 161 | - return CV_MAKETYPE((getDepth(Type2Type<Depth>())),(Channels)); | |
| 162 | - } | |
| 128 | + static int make() { return CV_MAKETYPE((getDepth(Type2Type<Depth>())),(Channels)); } | |
| 163 | 129 | }; |
| 164 | 130 | |
| 165 | 131 | #endif // OPENCVUTILS_OPENCVUTILS_H | ... | ... |