diff --git a/openbr/core/common.h b/openbr/core/common.h index 2c6c57c..166ee45 100644 --- a/openbr/core/common.h +++ b/openbr/core/common.h @@ -153,11 +153,10 @@ void MeanStdDev(const V &vals, double *mean, double *stddev) template class C, typename T> T Median(C vals, T *q1 = 0, T *q3 = 0) { - if (vals.isEmpty()) return std::numeric_limits::quiet_NaN(); qSort(vals); - if (q1 != 0) *q1 = vals[1*vals.size()/4]; - if (q3 != 0) *q3 = vals[3*vals.size()/4]; - return vals[vals.size()/2]; + if (q1 != 0) *q1 = vals.isEmpty() ? 0 : vals[1*vals.size()/4]; + if (q3 != 0) *q3 = vals.isEmpty() ? 0 : vals[3*vals.size()/4]; + return vals.isEmpty() ? 0 : vals[vals.size()/2]; } /*! diff --git a/openbr/core/fuse.cpp b/openbr/core/fuse.cpp index fe4136b..4a91c46 100644 --- a/openbr/core/fuse.cpp +++ b/openbr/core/fuse.cpp @@ -14,7 +14,6 @@ * limitations under the License. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include #include #include #include diff --git a/openbr/gui/imageviewer.cpp b/openbr/gui/imageviewer.cpp index a0dbe54..5512c78 100644 --- a/openbr/gui/imageviewer.cpp +++ b/openbr/gui/imageviewer.cpp @@ -36,7 +36,8 @@ void br::ImageViewer::setDefaultText(const QString &text) void br::ImageViewer::setImage(const QString &file, bool async) { - src = QImage(file); + if(file.isNull()) src = QImage(); // Gets rid of runtime FileEngine::open warning + else src = QImage(file); updatePixmap(async); } diff --git a/openbr/openbr_export.cpp b/openbr/openbr_export.cpp index 0696346..f6bab66 100644 --- a/openbr/openbr_export.cpp +++ b/openbr/openbr_export.cpp @@ -24,7 +24,7 @@ * OpenBR originated within The MITRE Corporation from a need to streamline the process of prototyping new algorithms. * The project was later published as open source software under the Apache 2 license and is free for academic and commercial use. * - * \image html "share/openbr/abstraction.svg" "The two principal software artifacts are the shared library 'openbr' and command line application 'br'." + * \image html "abstraction.svg" "The two principal software artifacts are the shared library 'openbr' and command line application 'br'." * * \section get_started Get Started * - \ref installation - \copybrief installation @@ -70,13 +70,13 @@ $ export DYLD_FRAMEWORK_PATH=../lib:${DYLD_FRAMEWORK_PATH} * No configuration is necessary! * * \section installation_license_dongle License Dongle - * If you were given a USB License Dongle, then dongle must be in the computer in order to use the SDK. + * In the unlikely event that you were given a USB License Dongle, then dongle must be in the computer in order to use the SDK. * No configuration of the dongle is needed. * * \section installation_done Start Working * To test for successful installation: \verbatim -$ cd bin/ +$ cd bin $ br -help \endverbatim */ @@ -180,7 +180,7 @@ $ br -help * $ cmake -G "MinGW Makefiles" -DBUILD_opencv_java=OFF -DBUILD_opencv_world=ON -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DWITH_FFMPEG=OFF -DCMAKE_BUILD_TYPE=Debug .. * $ mingw32-make * $ mingw32-make install - * $ cmake -DCMAKE_BUILD_TYPE=Release + * $ cmake -DCMAKE_BUILD_TYPE=Release .. * $ mingw32-make * $ mingw32-make install * $ mingw32-make clean @@ -244,7 +244,7 @@ $ br -help /*! * \page osx_clang OS X Mountain Lion - Clang/LLVM 3.1 - x64 * -# Download and install the latest "Xcode" and "Command Line Tools" from the Apple Developer Downloads page. - * -# Download CMake 2.8.10.2. + * -# Download CMake 2.8.10.2 * \code * $ cd ~/Downloads * $ tar -xf cmake-2.8.10.2.tar.gz @@ -253,22 +253,22 @@ $ br -help * $ make -j4 * $ sudo make install * $ cd .. - * $ rm -r cmake-2.8.10.2 + * $ rm -rf cmake-2.8.10.2* * \endcode - * -# Download OpenCV 2.4.4. + * -# Download OpenCV 2.4.5 * \code * $ cd ~/Downloads - * $ tar -xf OpenCV-2.4.4.tar.bz2 - * $ cd OpenCV-2.4.4 + * $ tar -xf opencv-2.4.5.tar.gz + * $ cd opencv-2.4.5 * $ mkdir build * $ cd build - * $ cmake -DBUILD_opencv_java=OFF -DBUILD_opencv_world=OFF -DCMAKE_BUILD_TYPE=Release .. + * $ cmake -DCMAKE_BUILD_TYPE=Release .. * $ make -j4 * $ sudo make install * $ cd ../.. - * $ rm -r OpenCV-2.4.4 + * $ rm -rf opencv-2.4.5* * \endcode - * -# Download Qt 5.0.1 and install. + * -# Download and install Qt 5.0.2 * -# Create a GitHub account, follow their instructions for setting up Git. * \code * $ git clone https://github.com/biometrics/openbr.git @@ -281,27 +281,34 @@ $ br -help * $ cd openbr * $ mkdir build * $ cd build - * $ cmake -DCMAKE_PREFIX_PATH=~/Qt5.0.1/5.0.1/clang_64 -DCMAKE_BUILD_TYPE=Release .. + * $ cmake -DCMAKE_PREFIX_PATH=~/Qt5.0.2/5.0.2/clang_64 -DCMAKE_BUILD_TYPE=Release .. * $ make -j4 * $ sudo make install * \endcode * -# Hack OpenBR! * -# Open Qt Creator IDE * \code - * $ open ~/Qt5.0.1/Qt\ Creator.app + * $ open ~/Qt5.0.2/Qt\ Creator.app * \endcode * -# From the Qt Creator "File" menu select "Open File or Project...". - * -# Select "~/openbr/CMakeLists.txt" then "Open". - * -# Browse to your prexisting build directory "~/openbr/build" then select "Continue". + * -# Select "openbr/CMakeLists.txt" then "Open". + * -# Browse to your prexisting build directory "openbr/build" then select "Continue". * -# Select "Run CMake" then "Done". * -# You're all set! You can find more information on Qt Creator here if you need. + * -# (Optional) Test OpenBR! + * \code + * $ cd openbr/scripts + * $ ./downloadDatasets.sh + * $ cd ../build + * $ make test + * \endcode * -# (Optional) Package OpenBR! * \code * $ cd openbr/build - * $ make package + * $ cpack -G TGZ * \endcode * -# (Optional) Build OpenBR documentation! - * -# Download Doxygen 1.8.2 and install: + * -# Download Doxygen 1.8.2 * \code * $ cd ~/Downloads * $ tar -xf doxygen-1.8.2.src.tar.gz @@ -310,9 +317,9 @@ $ br -help * $ make -j4 * $ sudo make install * $ cd .. - * $ rm -r doxygen-1.8.2 + * $ rm -rf doxygen-1.8.2* * \endcode - * -# Modify build settings and recompile: + * -# Modify build settings and recompile. * \code * $ cd openbr/build * $ cmake -DBR_BUILD_DOCUMENTATION=ON .. diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 0d6a8b1..393fb8f 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -389,8 +389,6 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) if (crossValidate > 0) srand(0); for (int i=newTemplates.size()-1; i>=0; i--) { - newTemplates[i].file.append(gallery.localMetadata()); - newTemplates[i].file.append(file.localMetadata()); newTemplates[i].file.set("Index", i+templates.size()); newTemplates[i].file.set("Gallery", gallery.name); diff --git a/openbr/plugins/distance.cpp b/openbr/plugins/distance.cpp index e082282..8781197 100644 --- a/openbr/plugins/distance.cpp +++ b/openbr/plugins/distance.cpp @@ -298,46 +298,6 @@ class IdenticalDistance : public Distance BR_REGISTER(Distance, IdenticalDistance) -class HeatMapDistance : public Distance -{ - Q_OBJECT - Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) - BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) - Q_PROPERTY(int rows READ get_rows WRITE set_rows RESET reset_rows STORED false) - BR_PROPERTY(int, rows, -1) - Q_PROPERTY(int cols READ get_cols WRITE set_cols RESET reset_cols STORED false) - BR_PROPERTY(int, cols, -1) - - void train(const TemplateList &src) - { - distance->train(src); - } - - - float compare(const Template &a, const Template &b) const - { - qFatal("HeatMap expects a TemplateList"); - - (void) a; (void) b; - } - - void compare(const TemplateList &target, const TemplateList &query, Output *output) const - { - if (rows*cols > target.size()) qFatal("Incompatible heatmap comparison dimensionality"); - - int index = 0; - for (int col = 0; col < cols; col++) { - for (int row = 0; row < rows; row++) { - float score = distance->compare(target[index],query[index]); - output->setRelative(score, row, col); - index++; - } - } - } -}; - -BR_REGISTER(Distance, HeatMapDistance) - } // namespace br #include "distance.moc" diff --git a/openbr/plugins/output.cpp b/openbr/plugins/output.cpp index 6c8233f..6f24f3a 100644 --- a/openbr/plugins/output.cpp +++ b/openbr/plugins/output.cpp @@ -97,33 +97,25 @@ BR_REGISTER(Output, csvOutput) class heatOutput : public MatrixOutput { Q_OBJECT - Q_PROPERTY(int rows READ get_rows WRITE set_rows RESET reset_rows STORED false) - BR_PROPERTY(int, rows, -1) - Q_PROPERTY(int cols READ get_cols WRITE set_cols RESET reset_cols STORED false) - BR_PROPERTY(int, cols, -1) + Q_PROPERTY(int patches READ get_patches WRITE set_patches RESET reset_patches STORED false) + BR_PROPERTY(int, patches, -1); ~heatOutput() { if (file.isNull() || targetFiles.isEmpty() || queryFiles.isEmpty()) return; - if (rows*cols > targetFiles.size()) qFatal("Incompatible heatmap output dimensionality"); - QStringList lines; - for (int col = 0; col < cols; col++) { - QStringList words; - for (int row = 0; row < rows; row++) - words.append(toString(row,col)); - lines.append(words.join(",")); + for (int i=0; idata.at(i, j); if (score == -std::numeric_limits::max()) continue; + if (crossModality) if(src[i].file.get("Modality") == src[j].file.get("Modality")) continue; if (labels[i] == labels[j]) genuineScores.append(score); else impostorScores.append(score); } @@ -181,9 +181,8 @@ class MatchProbabilityDistance : public Distance float compare(const Template &target, const Template &query) const { float rawScore = distance->compare(target, query); - return -log(rawScore+1); - //if (rawScore == -std::numeric_limits::max()) return rawScore; - //return mp(rawScore, gaussian); + if (rawScore == -std::numeric_limits::max()) return rawScore; + return mp(rawScore, gaussian); } void store(QDataStream &stream) const @@ -197,12 +196,110 @@ class MatchProbabilityDistance : public Distance distance->load(stream); stream >> mp; } + +protected: + BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) + BR_PROPERTY(bool, gaussian, true) + BR_PROPERTY(bool, crossModality, false) }; BR_REGISTER(Distance, MatchProbabilityDistance) /*! * \ingroup distances + * \brief Match Probability modification for heat maps \cite klare12 + * \author Scott Klum \cite sklum + */ +class HeatMapDistance : public Distance +{ + Q_OBJECT + Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) + Q_PROPERTY(bool gaussian READ get_gaussian WRITE set_gaussian RESET reset_gaussian STORED false) + Q_PROPERTY(bool crossModality READ get_crossModality WRITE set_crossModality RESET reset_crossModality STORED false) + Q_PROPERTY(int step READ get_step WRITE set_step RESET reset_step STORED false) + BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) + BR_PROPERTY(bool, gaussian, true) + BR_PROPERTY(bool, crossModality, false) + BR_PROPERTY(int, step, 1) + + QList mp; + + void train(const TemplateList &src) + { + distance->train(src); + + const QList labels = src.indexProperty("Subject"); + + QList patches; + + // Split src into list of TemplateLists of corresponding patches across all Templates + for (int i=0; i matrixOutput(MatrixOutput::make(FileList(patches[0].size()), FileList(patches[0].size()))); + + for (int i=0; icompare(patches[i], patches[i], matrixOutput.data()); + QList genuineScores, impostorScores; + genuineScores.reserve(step); + impostorScores.reserve(step); + for (int j=0; jdata.rows; j++) { + for (int k=0; kdata.at(j, k); + if (score == -std::numeric_limits::max()) continue; + if (crossModality) if(src[j*step].file.get("MODALITY") == src[k*step].file.get("MODALITY")) continue; + if (labels[j*step] == labels[k*step]) genuineScores.append(score); + else impostorScores.append(score); + } + } + + mp.append(MP(genuineScores, impostorScores)); + } + } + + float compare(const Template &target, const Template &query) const + { + (void) target; + (void) query; + qFatal("You did this wrong"); + + return 0; + } + + // Switch this to template list version, use compare(template, template) in + // heat map distance, and index into the proper match probability + void compare(const TemplateList &target, const TemplateList &query, Output *output) const + { + for (int i=0; icompare(target[i],query[i]); + if (rawScore == -std::numeric_limits::max()) output->setRelative(rawScore, i, 0); + else output->setRelative(mp[i](rawScore, gaussian), i, 0); + } + } + + void store(QDataStream &stream) const + { + distance->store(stream); + stream << mp; + } + + void load(QDataStream &stream) + { + distance->load(stream); + stream >> mp; + } +}; + +BR_REGISTER(Distance, HeatMapDistance) + +/*! + * \ingroup distances * \brief Linear normalizes of a distance so the mean impostor score is 0 and the mean genuine score is 1. * \author Josh Klontz \cite jklontz */ diff --git a/share/openbr/Doxyfile.in b/share/openbr/Doxyfile.in index 22c56b8..26151d7 100644 --- a/share/openbr/Doxyfile.in +++ b/share/openbr/Doxyfile.in @@ -755,7 +755,7 @@ EXAMPLE_RECURSIVE = YES # directories that contain image that are included in the documentation (see # the \image command). -IMAGE_PATH = ${CMAKE_SOURCE_DIR} +IMAGE_PATH = ${CMAKE_SOURCE_DIR}/share/openbr # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program