From d723e2caf096895d5f139e2bf6e167ab6299c55e Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Wed, 30 Oct 2013 13:57:43 -0400 Subject: [PATCH] played around with weighing the HoG vectors based on magnitude, didn't see much of an impact --- openbr/plugins/hist.cpp | 31 +++++++++++++++++++++++++++---- openbr/plugins/integral.cpp | 19 ++++++++++++++----- scripts/integralFaceRecognition-PCSO.sh | 3 +++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100755 scripts/integralFaceRecognition-PCSO.sh diff --git a/openbr/plugins/hist.cpp b/openbr/plugins/hist.cpp index 5563ff6..6fc3bb9 100644 --- a/openbr/plugins/hist.cpp +++ b/openbr/plugins/hist.cpp @@ -86,13 +86,36 @@ class BinTransform : public UntrainableTransform void project(const Template &src, Template &dst) const { const double floor = ((src.m().depth() == CV_32F) || (src.m().depth() == CV_64F)) ? -0.5 : 0; - src.m().convertTo(dst, bins > 256 ? CV_16U : CV_8U, bins/(max-min), floor); + + Mat weights, vals; + const int channels = src.m().channels(); + if (channels == 1) { + vals = src; + } else if (channels == 2) { + // If there are two channels, the first is channel is assumed to be a weight vector + // and the second channel contains the vectors we would like to bin. + vector mv; + cv::split(src, mv); + weights = mv[0]; + weights.convertTo(weights, CV_32F); + vals = mv[1]; + } else { + qFatal("Invalid channel count: %d", channels); + } + + vals.convertTo(dst, bins > 256 ? CV_16U : CV_8U, bins/(max-min), floor); if (!split) return; - Mat input = dst; QList outputs; outputs.reserve(bins); - for (int i=0; i mv; + if ((channel == Magnitude) || (channel == MagnitudeAndAngle)) { + const float theoreticalMaxMagnitude = sqrt(2*pow(float(2*(3+10+3)*255), 2.f)); + mv.push_back(magnitude / theoreticalMaxMagnitude); + } if ((channel == Angle) || (channel == MagnitudeAndAngle)) - dst.append(angle); + mv.push_back(angle); + Mat result; + merge(mv, result); + dst.append(result); } }; diff --git a/scripts/integralFaceRecognition-PCSO.sh b/scripts/integralFaceRecognition-PCSO.sh new file mode 100755 index 0000000..73c4b7e --- /dev/null +++ b/scripts/integralFaceRecognition-PCSO.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +br -algorithm "{PP5Register+Affine(128,128,0.25,0.35)}+Cvt(Gray)+Gradient+Bin(0,360,9,true)+Merge+Integral+CvtFloat+RecursiveIntegralSampler(4,2,8,LDA(.98)+Normalize(L1))+Cat+PCA(768)+Normalize(L1)+Quantize:UCharL1" -path ~/data/PCSO -train ../data/PCSO/sigset/PCSO_2x1k_train.xml -compare ../data/PCSO/sigset/PCSO_2x1k_test.xml . scores.mtx -eval scores.mtx scores.csv \ No newline at end of file -- libgit2 0.21.4