Commit d723e2caf096895d5f139e2bf6e167ab6299c55e
1 parent
4e02e315
played around with weighing the HoG vectors based on magnitude, didn't see much of an impact
Showing
3 changed files
with
44 additions
and
9 deletions
openbr/plugins/hist.cpp
| ... | ... | @@ -86,13 +86,36 @@ class BinTransform : public UntrainableTransform |
| 86 | 86 | void project(const Template &src, Template &dst) const |
| 87 | 87 | { |
| 88 | 88 | const double floor = ((src.m().depth() == CV_32F) || (src.m().depth() == CV_64F)) ? -0.5 : 0; |
| 89 | - src.m().convertTo(dst, bins > 256 ? CV_16U : CV_8U, bins/(max-min), floor); | |
| 89 | + | |
| 90 | + Mat weights, vals; | |
| 91 | + const int channels = src.m().channels(); | |
| 92 | + if (channels == 1) { | |
| 93 | + vals = src; | |
| 94 | + } else if (channels == 2) { | |
| 95 | + // If there are two channels, the first is channel is assumed to be a weight vector | |
| 96 | + // and the second channel contains the vectors we would like to bin. | |
| 97 | + vector<Mat> mv; | |
| 98 | + cv::split(src, mv); | |
| 99 | + weights = mv[0]; | |
| 100 | + weights.convertTo(weights, CV_32F); | |
| 101 | + vals = mv[1]; | |
| 102 | + } else { | |
| 103 | + qFatal("Invalid channel count: %d", channels); | |
| 104 | + } | |
| 105 | + | |
| 106 | + vals.convertTo(dst, bins > 256 ? CV_16U : CV_8U, bins/(max-min), floor); | |
| 90 | 107 | if (!split) return; |
| 91 | 108 | |
| 92 | - Mat input = dst; | |
| 93 | 109 | QList<Mat> outputs; outputs.reserve(bins); |
| 94 | - for (int i=0; i<bins; i++) | |
| 95 | - outputs.append(input == i); // Note: Matrix elements are 0 or 255 | |
| 110 | + for (int i=0; i<bins; i++) { | |
| 111 | + Mat output = (dst == i); | |
| 112 | + if (weights.data) { | |
| 113 | + output.convertTo(output, CV_32F); | |
| 114 | + multiply(output, weights, output); | |
| 115 | + output.convertTo(output, CV_8U); | |
| 116 | + } | |
| 117 | + outputs.append(output); | |
| 118 | + } | |
| 96 | 119 | dst.clear(); dst.append(outputs); |
| 97 | 120 | } |
| 98 | 121 | }; | ... | ... |
openbr/plugins/integral.cpp
| ... | ... | @@ -212,6 +212,9 @@ class RecursiveIntegralSamplerTransform : public Transform |
| 212 | 212 | |
| 213 | 213 | void train(const TemplateList &src) |
| 214 | 214 | { |
| 215 | + if (src.first().m().depth() != CV_32S) | |
| 216 | + qFatal("Expected CV_32S depth!"); | |
| 217 | + | |
| 215 | 218 | if (subTransform != NULL) { |
| 216 | 219 | TemplateList subSrc; subSrc.reserve(src.size()); |
| 217 | 220 | foreach (const Template &t, src) |
| ... | ... | @@ -287,13 +290,19 @@ private: |
| 287 | 290 | void project(const Template &src, Template &dst) const |
| 288 | 291 | { |
| 289 | 292 | Mat dx, dy, magnitude, angle; |
| 290 | - Sobel(src, dx, CV_32F, 1, 0); | |
| 291 | - Sobel(src, dy, CV_32F, 0, 1); | |
| 293 | + Sobel(src, dx, CV_32F, 1, 0, CV_SCHARR); | |
| 294 | + Sobel(src, dy, CV_32F, 0, 1, CV_SCHARR); | |
| 292 | 295 | cartToPolar(dx, dy, magnitude, angle, true); |
| 293 | - if ((channel == Magnitude) || (channel == MagnitudeAndAngle)) | |
| 294 | - dst.append(magnitude); | |
| 296 | + vector<Mat> mv; | |
| 297 | + if ((channel == Magnitude) || (channel == MagnitudeAndAngle)) { | |
| 298 | + const float theoreticalMaxMagnitude = sqrt(2*pow(float(2*(3+10+3)*255), 2.f)); | |
| 299 | + mv.push_back(magnitude / theoreticalMaxMagnitude); | |
| 300 | + } | |
| 295 | 301 | if ((channel == Angle) || (channel == MagnitudeAndAngle)) |
| 296 | - dst.append(angle); | |
| 302 | + mv.push_back(angle); | |
| 303 | + Mat result; | |
| 304 | + merge(mv, result); | |
| 305 | + dst.append(result); | |
| 297 | 306 | } |
| 298 | 307 | }; |
| 299 | 308 | ... | ... |
scripts/integralFaceRecognition-PCSO.sh
0 → 100755
| 1 | +#!/bin/sh | |
| 2 | + | |
| 3 | +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 | |
| 0 | 4 | \ No newline at end of file | ... | ... |