Commit 08b73def2f0e365c7bbcfc4f2557b78855890565
1 parent
bbc43870
Generalized the raw format
Showing
1 changed file
with
9 additions
and
35 deletions
openbr/plugins/format/raw.cpp
| ... | ... | @@ -26,49 +26,25 @@ namespace br |
| 26 | 26 | * \ingroup formats |
| 27 | 27 | * \brief RAW format |
| 28 | 28 | * |
| 29 | - * \br_link http://www.nist.gov/srd/nistsd27.cfm | |
| 30 | - * \author Josh Klontz \cite jklontz | |
| 29 | + * \author Scott Klum \cite sklum | |
| 31 | 30 | */ |
| 32 | 31 | class rawFormat : public Format |
| 33 | 32 | { |
| 34 | 33 | Q_OBJECT |
| 35 | - static QHash<QString, QHash<QString,QSize> > imageSizes; // QHash<Path, QHash<File,Size> > | |
| 36 | 34 | |
| 37 | 35 | Template read() const |
| 38 | 36 | { |
| 39 | - QString path = file.path(); | |
| 40 | - if (!imageSizes.contains(path)) { | |
| 41 | - static QMutex mutex; | |
| 42 | - QMutexLocker locker(&mutex); | |
| 43 | - | |
| 44 | - if (!imageSizes.contains(path)) { | |
| 45 | - const QString imageSize = path+"/ImageSize.txt"; | |
| 46 | - QStringList lines; | |
| 47 | - if (QFileInfo(imageSize).exists()) { | |
| 48 | - lines = QtUtils::readLines(imageSize); | |
| 49 | - lines.removeFirst(); // Remove header | |
| 50 | - } | |
| 51 | - | |
| 52 | - QHash<QString,QSize> sizes; | |
| 53 | - QRegExp whiteSpace("\\s+"); | |
| 54 | - foreach (const QString &line, lines) { | |
| 55 | - QStringList words = line.split(whiteSpace); | |
| 56 | - if (words.size() != 3) continue; | |
| 57 | - sizes.insert(words[0], QSize(words[2].toInt(), words[1].toInt())); | |
| 58 | - } | |
| 59 | - | |
| 60 | - imageSizes.insert(path, sizes); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | 37 | QByteArray data; |
| 65 | 38 | QtUtils::readFile(file, data); |
| 66 | 39 | |
| 67 | - QSize size = imageSizes[path][file.baseName()]; | |
| 68 | - if (!size.isValid()) size = QSize(800,768); | |
| 69 | - if (data.size() != size.width() * size.height()) | |
| 70 | - qFatal("Expected %d*%d bytes, got %d.", size.height(), size.width(), data.size()); | |
| 71 | - return Template(file, Mat(size.height(), size.width(), CV_8UC1, data.data()).clone()); | |
| 40 | + // The raw file format has no header information, so one must specify resolution | |
| 41 | + QSize size = size = QSize(file.get<int>("width"),file.get<int>("height")); | |
| 42 | + Template t(file); | |
| 43 | + QList<Mat> matrices; | |
| 44 | + const int bytes = size.width()*size.height(); | |
| 45 | + for (int i=0; i<data.size()/(size.height()*size.width()); i++) | |
| 46 | + t.append(Mat(size.height(), size.width(), CV_8UC1, data.data()+bytes*i).clone()); | |
| 47 | + return t; | |
| 72 | 48 | } |
| 73 | 49 | |
| 74 | 50 | void write(const Template &t) const |
| ... | ... | @@ -77,8 +53,6 @@ class rawFormat : public Format |
| 77 | 53 | } |
| 78 | 54 | }; |
| 79 | 55 | |
| 80 | -QHash<QString, QHash<QString,QSize> > rawFormat::imageSizes; | |
| 81 | - | |
| 82 | 56 | BR_REGISTER(Format, rawFormat) |
| 83 | 57 | |
| 84 | 58 | } // namespace br | ... | ... |