From 3c3e21d90dc07eea3af4fab864297a433324726b Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Sat, 20 Apr 2013 20:03:48 -0400 Subject: [PATCH] mtxOutput now limited by disk size instead of memory size --- openbr/openbr_plugin.h | 4 ++-- openbr/plugins/output.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index f6a2419..39dcd2e 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -906,8 +906,8 @@ public: bool selfSimilar; /*!< \brief \c true if the \em targetFiles == \em queryFiles, \c false otherwise. */ virtual ~Output() {} - void setBlock(int rowBlock, int columnBlock); /*!< \brief Set the current block. */ - void setRelative(float value, int i, int j); /*!< \brief Set a score relative to the current block. */ + virtual void setBlock(int rowBlock, int columnBlock); /*!< \brief Set the current block. */ + virtual void setRelative(float value, int i, int j); /*!< \brief Set a score relative to the current block. */ static Output *make(const File &file, const FileList &targetFiles, const FileList &queryFiles); /*!< \brief Make an output from a file and gallery/probe file lists. */ static void reformat(const FileList &targetFiles, const FileList &queryFiles, const File &simmat, const File &output); /*!< \brief Create an output from a similarity matrix and file lists. */ diff --git a/openbr/plugins/output.cpp b/openbr/plugins/output.cpp index d8692fb..7f873e3 100644 --- a/openbr/plugins/output.cpp +++ b/openbr/plugins/output.cpp @@ -138,17 +138,75 @@ BR_REGISTER(Output, meltOutput) * \brief \ref simmat output. * \author Josh Klontz \cite jklontz */ -class mtxOutput : public MatrixOutput +class mtxOutput : public Output { Q_OBJECT + int headerSize, rowBlock, columnBlock; + cv::Mat blockScores; ~mtxOutput() { - if (file.isNull() || targetFiles.isEmpty() || queryFiles.isEmpty()) return; - BEE::writeSimmat(data, - file.name, - targetFiles.first().get("Gallery", "Unknown_Target"), - queryFiles.first().get("Gallery", "Unknown_Query")); + writeBlock(); + } + + void setBlock(int rowBlock, int columnBlock) + { + if ((rowBlock == 0) && (columnBlock == 0)) { + // Initialize the file + QFile f(file); + QtUtils::touchDir(f); + if (!f.open(QFile::WriteOnly)) + qFatal("Unable to open %s for writing.", qPrintable(file)); + const int endian = 0x12345678; + QByteArray header; + header.append("S2\n"); + header.append(qPrintable(targetFiles.first().get("Gallery", "Unknown_Target"))); + header.append("\n"); + header.append(qPrintable(queryFiles.first().get("Gallery", "Unknown_Query"))); + header.append("\nMF "); + header.append(qPrintable(QString::number(queryFiles.size()))); + header.append(" "); + header.append(qPrintable(QString::number(targetFiles.size()))); + header.append(" "); + header.append(QByteArray((const char*)&endian, 4)); + header.append("\n"); + headerSize = f.write(header); + const float defaultValue = -std::numeric_limits::max(); + for (int i=0; irowBlock = rowBlock; + this->columnBlock = columnBlock; + blockScores = cv::Mat(std::min(queryFiles.size()-rowBlock*Globals->blockSize, Globals->blockSize), + std::min(targetFiles.size()-columnBlock*Globals->blockSize, Globals->blockSize), + CV_32FC1); + } + + void setRelative(float value, int i, int j) + { + blockScores.at(i,j) = value; + } + + void set(float value, int i, int j) + { + (void) value; (void) i; (void) j; + qFatal("Logic error."); + } + + void writeBlock() + { + QFile f(file); + if (!f.open(QFile::ReadWrite)) + qFatal("Unable to open %s for modifying.", qPrintable(file)); + for (int i=0; iblockSize+i)*targetFiles.size()+(columnBlock*Globals->blockSize))); + f.write((const char*)blockScores.row(i).data, sizeof(float)*blockScores.cols); + } + f.close(); } }; -- libgit2 0.21.4