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/misc.cpp b/openbr/plugins/misc.cpp index 765568d..35dd638 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -424,19 +424,21 @@ BR_REGISTER(Transform, SubjectTransform) /*! * \ingroup transforms - * \brief Remove templates with the specified file extension. + * \brief Remove templates with the specified file extension or metadata value. * \author Josh Klontz \cite jklontz */ class RemoveTemplatesTransform : public UntrainableMetaTransform { Q_OBJECT Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false) + Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false) BR_PROPERTY(QString, regexp, "") + BR_PROPERTY(QString, key, "") void project(const Template &src, Template &dst) const { const QRegularExpression re(regexp); - const QRegularExpressionMatch match = re.match(src.file.suffix()); + const QRegularExpressionMatch match = re.match(key.isEmpty() ? src.file.suffix() : src.file.get(key)); if (match.hasMatch()) dst = Template(); else dst = src; } 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(); } };