From 3d628fa96fb02e555f96c4d8ee11d528338778ee Mon Sep 17 00:00:00 2001 From: Charles Otto Date: Wed, 5 Mar 2014 11:36:18 -0500 Subject: [PATCH] Distance gallery and output incremental operations from Globals->blockSize --- openbr/openbr_plugin.cpp | 10 ++++++++-- openbr/openbr_plugin.h | 11 +++++++++-- openbr/plugins/gallery.cpp | 6 +++--- openbr/plugins/output.cpp | 10 ++++++---- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 1740bde..0f2cb82 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -1101,13 +1101,19 @@ void Output::initialize(const FileList &targetFiles, const FileList &queryFiles) { this->targetFiles = targetFiles; this->queryFiles = queryFiles; + if (this->blockRows == -1) + blockRows = Globals->blockSize; + + if (this->blockCols == -1) + blockCols = Globals->blockSize; + selfSimilar = (queryFiles == targetFiles) && (targetFiles.size() > 1) && (queryFiles.size() > 1); } void Output::setBlock(int rowBlock, int columnBlock) { - offset = QPoint((columnBlock == -1) ? 0 : Globals->blockSize*columnBlock, - (rowBlock == -1) ? 0 : Globals->blockSize*rowBlock); + offset = QPoint((columnBlock == -1) ? 0 : blockCols*columnBlock, + (rowBlock == -1) ? 0 : blockRows*rowBlock); if (!next.isNull()) next->setBlock(rowBlock, columnBlock); } diff --git a/openbr/openbr_plugin.h b/openbr/openbr_plugin.h index 3f84d7e..01de310 100644 --- a/openbr/openbr_plugin.h +++ b/openbr/openbr_plugin.h @@ -996,6 +996,11 @@ class BR_EXPORT Output : public Object Q_OBJECT public: + Q_PROPERTY(int blockRows READ get_blockRows WRITE set_blockRows RESET reset_blockRows STORED false) + Q_PROPERTY(int blockCols READ get_blockCols WRITE set_blockCols RESET reset_blockCols STORED false) + BR_PROPERTY(int, blockRows, -1) + BR_PROPERTY(int, blockCols, -1) + FileList targetFiles; /*!< \brief List of files representing the gallery templates. */ FileList queryFiles; /*!< \brief List of files representing the probe templates. */ bool selfSimilar; /*!< \brief \c true if the \em targetFiles == \em queryFiles, \c false otherwise. */ @@ -1074,9 +1079,11 @@ public: */ class BR_EXPORT Gallery : public Object { - Q_OBJECT - + Q_OBJECT public: + Q_PROPERTY(int readBlockSize READ get_readBlockSize WRITE set_readBlockSize RESET reset_readBlockSize STORED false) + BR_PROPERTY(int, readBlockSize, Globals->blockSize) + virtual ~Gallery() {} TemplateList read(); /*!< \brief Retrieve all the stored templates. */ FileList files(); /*!< \brief Retrieve all the stored template files. */ diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index fbc4950..a57aae2 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -123,7 +123,7 @@ class galGallery : public Gallery gallery.seek(0); TemplateList templates; - while ((templates.size() < Globals->blockSize) && !stream.atEnd()) { + while ((templates.size() < readBlockSize) && !stream.atEnd()) { Template m; stream >> m; templates.append(m); @@ -348,8 +348,8 @@ class memGallery : public Gallery MemoryGalleries::aligned[file] = true; } - TemplateList templates = MemoryGalleries::galleries[file].mid(block*Globals->blockSize, Globals->blockSize); - *done = (templates.size() < Globals->blockSize); + TemplateList templates = MemoryGalleries::galleries[file].mid(block*readBlockSize, readBlockSize); + *done = (templates.size() < readBlockSize); block = *done ? 0 : block+1; return templates; } diff --git a/openbr/plugins/output.cpp b/openbr/plugins/output.cpp index b9a290a..b58bf49 100644 --- a/openbr/plugins/output.cpp +++ b/openbr/plugins/output.cpp @@ -215,9 +215,11 @@ class mtxOutput : public Output this->rowBlock = 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); + + int matrixRows = std::min(queryFiles.size()-rowBlock*this->blockRows, blockRows); + int matrixCols = std::min(targetFiles.size()-columnBlock*this->blockCols, blockCols); + + blockScores = cv::Mat(matrixRows, matrixCols, CV_32FC1); } void setRelative(float value, int i, int j) @@ -237,7 +239,7 @@ class mtxOutput : public Output 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.seek(headerSize + sizeof(float)*(quint64(rowBlock*this->blockRows+i)*targetFiles.size()+(columnBlock*this->blockCols))); f.write((const char*)blockScores.row(i).data, sizeof(float)*blockScores.cols); } f.close(); -- libgit2 0.21.4