Commit 3080864adf84b77df8bd33852fb216ab3bc49926

Authored by Josh Klontz
1 parent 044fc4e6

remote ltp

Showing 1 changed file with 0 additions and 122 deletions
openbr/plugins/imgproc/ltp.cpp deleted
1   -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2   - * Copyright 2012 The MITRE Corporation *
3   - * *
4   - * Licensed under the Apache License, Version 2.0 (the "License"); *
5   - * you may not use this file except in compliance with the License. *
6   - * You may obtain a copy of the License at *
7   - * *
8   - * http://www.apache.org/licenses/LICENSE-2.0 *
9   - * *
10   - * Unless required by applicable law or agreed to in writing, software *
11   - * distributed under the License is distributed on an "AS IS" BASIS, *
12   - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13   - * See the License for the specific language governing permissions and *
14   - * limitations under the License. *
15   - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16   -
17   -#include <opencv2/imgproc/imgproc.hpp>
18   -#include <opencv2/imgproc/imgproc_c.h>
19   -#include <limits>
20   -
21   -#include <openbr/plugins/openbr_internal.h>
22   -
23   -using namespace cv;
24   -
25   -namespace br
26   -{
27   -
28   -/*!
29   - * \ingroup transforms
30   - * \brief DOCUMENT ME
31   - * \br_paper Tan, Xiaoyang, and Bill Triggs.
32   - * "Enhanced local texture feature sets for face recognition under difficult lighting conditions."
33   - * Analysis and Modeling of Faces and Gestures. Springer Berlin Heidelberg, 2007. 168-182.
34   - * \author Brendan Klare \cite bklare
35   - * \author Josh Klontz \cite jklontz
36   - */
37   -class LTPTransform : public UntrainableTransform
38   -{
39   - Q_OBJECT
40   - Q_PROPERTY(int radius READ get_radius WRITE set_radius RESET reset_radius STORED false)
41   - Q_PROPERTY(float threshold READ get_threshold WRITE set_threshold RESET reset_threshold STORED false)
42   - BR_PROPERTY(int, radius, 1)
43   - BR_PROPERTY(float, threshold, 0.1F)
44   -
45   - unsigned short lut[8][3];
46   - uchar null;
47   -
48   - void init()
49   - {
50   - unsigned short cnt = 0;
51   - for (int i = 0; i < 8; i++) {
52   - for (int j = 0; j < 3; j++)
53   - lut[i][j] = cnt++;
54   - cnt++; //we skip the 4th number (only three patterns)
55   - }
56   - }
57   -
58   - void project(const Template &src, Template &dst) const
59   - {
60   - Mat m; src.m().convertTo(m, CV_32F); assert(m.isContinuous() && (m.channels() == 1));
61   -
62   - Mat n(m.rows, m.cols, CV_16U);
63   - n = null;
64   - float thresholdNeg = -1.0 * threshold; //compute once (can move to init)
65   -
66   - const float *p = (const float*)m.ptr();
67   - float diff;
68   - for (int r=radius; r<m.rows-radius; r++) {
69   - for (int c=radius; c<m.cols-radius; c++) {
70   - const float cval = (p[(r+0*radius)*m.cols+c+0*radius]);
71   -
72   - diff = p[(r-1*radius)*m.cols+c-1*radius] - cval;
73   - if (diff > threshold) n.at<unsigned short>(r,c) = lut[0][0];
74   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) = lut[0][1];
75   - else n.at<unsigned short>(r,c) = lut[0][2];
76   -
77   - diff = p[(r-1*radius)*m.cols+c+0*radius] - cval;
78   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[1][0];
79   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[1][1];
80   - else n.at<unsigned short>(r,c) += lut[1][2];
81   -
82   - diff = p[(r-1*radius)*m.cols+c+1*radius] - cval;
83   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[2][0];
84   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[2][1];
85   - else n.at<unsigned short>(r,c) += lut[2][2];
86   -
87   - diff = p[(r+0*radius)*m.cols+c+1*radius] - cval;
88   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[3][0];
89   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[3][1];
90   - else n.at<unsigned short>(r,c) += lut[3][2];
91   -
92   - diff = p[(r+1*radius)*m.cols+c+1*radius] - cval;
93   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[4][0];
94   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[4][1];
95   - else n.at<unsigned short>(r,c) += lut[4][2];
96   -
97   - diff = p[(r+1*radius)*m.cols+c+0*radius] - cval;
98   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[5][0];
99   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[5][1];
100   - else n.at<unsigned short>(r,c) += lut[5][2];
101   -
102   - diff = p[(r+1*radius)*m.cols+c-1*radius] - cval;
103   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[6][0];
104   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[6][1];
105   - else n.at<unsigned short>(r,c) += lut[6][2];
106   -
107   - diff = p[(r+0*radius)*m.cols+c-1*radius] - cval;
108   - if (diff > threshold) n.at<unsigned short>(r,c) += lut[7][0];
109   - else if (diff < thresholdNeg) n.at<unsigned short>(r,c) += lut[7][1];
110   - else n.at<unsigned short>(r,c) += lut[7][2];
111   - }
112   - }
113   -
114   - dst += n;
115   - }
116   -};
117   -
118   -BR_REGISTER(Transform, LTPTransform)
119   -
120   -} // namespace br
121   -
122   -#include "imgproc/ltp.moc"