Commit 2fcf4ff992dd1b92f43ab3d6de1cef081e8e18de
1 parent
8d288efe
implemented .bin format
Showing
1 changed file
with
40 additions
and
0 deletions
sdk/plugins/format.cpp
| @@ -32,6 +32,46 @@ using namespace cv; | @@ -32,6 +32,46 @@ using namespace cv; | ||
| 32 | 32 | ||
| 33 | /*! | 33 | /*! |
| 34 | * \ingroup formats | 34 | * \ingroup formats |
| 35 | + * \brief A simple binary matrix format. | ||
| 36 | + * \author Josh Klonyz \cite jklontz | ||
| 37 | + * First 4 bytes indicate the number of rows. | ||
| 38 | + * Second 4 bytes indicate the number of columns. | ||
| 39 | + * The rest of the bytes are 32-bit floating data elements. | ||
| 40 | + */ | ||
| 41 | +class binFormat : public Format | ||
| 42 | +{ | ||
| 43 | + Q_OBJECT | ||
| 44 | + | ||
| 45 | + Template read() const | ||
| 46 | + { | ||
| 47 | + QByteArray data; | ||
| 48 | + QtUtils::readFile(file, data); | ||
| 49 | + return Template(file, Mat(((quint32*)data.data())[0], | ||
| 50 | + ((quint32*)data.data())[1], | ||
| 51 | + CV_32FC1, | ||
| 52 | + data.data()+8).clone()); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + void write(const Template &t) const | ||
| 56 | + { | ||
| 57 | + Mat m; | ||
| 58 | + t.m().convertTo(m, CV_32F); | ||
| 59 | + if (m.channels() != 1) qFatal("binFormat::write only supports single channel matrices."); | ||
| 60 | + | ||
| 61 | + QByteArray data; | ||
| 62 | + QDataStream stream(&data, QFile::WriteOnly); | ||
| 63 | + stream.writeRawData((const char*)&m.rows, 4); | ||
| 64 | + stream.writeRawData((const char*)&m.cols, 4); | ||
| 65 | + stream.writeRawData((const char*)m.data, 4*m.rows*m.cols); | ||
| 66 | + | ||
| 67 | + QtUtils::writeFile(file, data); | ||
| 68 | + } | ||
| 69 | +}; | ||
| 70 | + | ||
| 71 | +BR_REGISTER(Format, binFormat) | ||
| 72 | + | ||
| 73 | +/*! | ||
| 74 | + * \ingroup formats | ||
| 35 | * \brief Reads a comma separated value file. | 75 | * \brief Reads a comma separated value file. |
| 36 | * \author Josh Klontz \cite jklontz | 76 | * \author Josh Klontz \cite jklontz |
| 37 | */ | 77 | */ |