From 1952d8269d9432eb4c7b16e4991ef2a01c41c866 Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Fri, 15 Mar 2013 16:39:06 -0400 Subject: [PATCH] bug fixes --- sdk/core/opencvutils.cpp | 1 + sdk/plugins/algorithms.cpp | 2 +- sdk/plugins/cvt.cpp | 17 +++++++++++------ sdk/plugins/eigen3.cpp | 10 +++++----- sdk/plugins/integral.cpp | 6 ++---- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/sdk/core/opencvutils.cpp b/sdk/core/opencvutils.cpp index 9a178f3..8dc6f4c 100644 --- a/sdk/core/opencvutils.cpp +++ b/sdk/core/opencvutils.cpp @@ -143,6 +143,7 @@ Mat OpenCVUtils::toMatByRow(const QList &src) int rows = 0; foreach (const Mat &m, src) rows += m.rows; int cols = src.first().cols; + if (cols == 0) qFatal("Columnless matrix!"); int type = src.first().type(); Mat dst(rows, cols, type); diff --git a/sdk/plugins/algorithms.cpp b/sdk/plugins/algorithms.cpp index 526bcb7..cd513b2 100644 --- a/sdk/plugins/algorithms.cpp +++ b/sdk/plugins/algorithms.cpp @@ -50,7 +50,7 @@ class AlgorithmsInitializer : public Initializer Globals->abbreviations.insert("SmallSIFT", "Open+LimitSize(512)+KeyPointDetector(SIFT)+KeyPointDescriptor(SIFT):KeyPointMatcher(BruteForce)"); Globals->abbreviations.insert("SmallSURF", "Open+LimitSize(512)+KeyPointDetector(SURF)+KeyPointDescriptor(SURF):KeyPointMatcher(BruteForce)"); Globals->abbreviations.insert("ColorHist", "Open+LimitSize(512)!EnsureChannels(3)+SplitChannels+Hist(256,0,8)+Cat+Normalize(L1):L2"); - Globals->abbreviations.insert("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat+WordWise(RowWisePCA(8)+RowWiseMeanCenter+Binarize,Identity):L2"); + Globals->abbreviations.insert("IHH", "Open+(RG+MAdd(0.5))/(Cvt(Gray)+Gradient+Bin(0,360,8,true))+Merge+Integral+IntegralSampler+CvtFloat+WordWise(RowWisePCA(8)+RowWiseMeanCenter+Binarize,RowWisePCA):L2"); // Hash Globals->abbreviations.insert("FileName", "Name+Identity:Identical"); diff --git a/sdk/plugins/cvt.cpp b/sdk/plugins/cvt.cpp index b48ed56..52314fa 100644 --- a/sdk/plugins/cvt.cpp +++ b/sdk/plugins/cvt.cpp @@ -181,12 +181,17 @@ class RGTransform : public UntrainableTransform for (int i=0; i(i,j); - uchar& b = v[0]; - uchar& g = v[1]; - uchar& r = v[2]; - - R.at(i, j) = saturate_cast(255.0*r/(r+g+b)); - G.at(i, j) = saturate_cast(255.0*g/(r+g+b)); + const int b = v[0]; + const int g = v[1]; + const int r = v[2]; + const int sum = b + g + r; + if (sum > 0) { + R.at(i, j) = saturate_cast(255.0*r/(r+g+b)); + G.at(i, j) = saturate_cast(255.0*g/(r+g+b)); + } else { + R.at(i, j) = 0; + G.at(i, j) = 0; + } } dst.append(R); diff --git a/sdk/plugins/eigen3.cpp b/sdk/plugins/eigen3.cpp index 1368d25..8aede98 100644 --- a/sdk/plugins/eigen3.cpp +++ b/sdk/plugins/eigen3.cpp @@ -145,15 +145,15 @@ protected: if (keep < 1) { // Keep eigenvectors that retain a certain energy percentage. - double totalEnergy = allEVals.sum(); + const double totalEnergy = allEVals.sum(); if (totalEnergy == 0) { keep = 0; } else { double currentEnergy = 0; - int i; - for (i=1; i<=allEVals.rows(); i++) { - currentEnergy += allEVals(allEVals.rows()-i); - if (currentEnergy / totalEnergy >= keep) break; + int i=0; + while ((currentEnergy / totalEnergy < keep) && (i < allEVals.rows())) { + currentEnergy += allEVals(allEVals.rows()-(i+1)); + i++; } keep = i - drop; } diff --git a/sdk/plugins/integral.cpp b/sdk/plugins/integral.cpp index 3329454..4e75367 100644 --- a/sdk/plugins/integral.cpp +++ b/sdk/plugins/integral.cpp @@ -159,9 +159,7 @@ class WordWiseTransform : public Transform void project(const Template &src, Template &dst) const { - Template reworded; - getWords->project(src, reworded); - byWord->project(reworded, dst); + byWord->project(reword(src), dst); } Template reword(const Template &src) const @@ -177,7 +175,7 @@ class WordWiseTransform : public Transform QVector indicies(numWords, 0); for (int i=0; i(i,0); - reworded[word].row(indicies[word]++) = src.m().row(i); + src.m().row(i).copyTo(reworded[word].row(indicies[word]++)); } return reworded; } -- libgit2 0.21.4