16 #include <stdint-gcc.h> 28 void FORB::meanValue(
const std::vector<FORB::pDescriptor> &descriptors,
31 if(descriptors.empty())
36 else if(descriptors.size() == 1)
38 mean = descriptors[0]->clone();
42 vector<int> sum(FORB::L * 8, 0);
44 for(
size_t i = 0; i < descriptors.size(); ++i)
46 const cv::Mat &
d = *descriptors[i];
47 const unsigned char *p = d.ptr<
unsigned char>();
49 for(
int j = 0; j < d.cols; ++j, ++p)
51 if(*p & (1 << 7)) ++sum[ j*8 ];
52 if(*p & (1 << 6)) ++sum[ j*8 + 1 ];
53 if(*p & (1 << 5)) ++sum[ j*8 + 2 ];
54 if(*p & (1 << 4)) ++sum[ j*8 + 3 ];
55 if(*p & (1 << 3)) ++sum[ j*8 + 4 ];
56 if(*p & (1 << 2)) ++sum[ j*8 + 5 ];
57 if(*p & (1 << 1)) ++sum[ j*8 + 6 ];
58 if(*p & (1)) ++sum[ j*8 + 7 ];
62 mean = cv::Mat::zeros(1, FORB::L, CV_8U);
63 unsigned char *p = mean.ptr<
unsigned char>();
65 const int N2 = (int)descriptors.size() / 2 + descriptors.size() % 2;
66 for(
size_t i = 0; i < sum.size(); ++i)
71 *p |= 1 << (7 - (i % 8));
87 const int *pa = a.ptr<int32_t>();
88 const int *pb = b.ptr<int32_t>();
92 for(
int i=0; i<8; i++, pa++, pb++)
94 unsigned int v = *pa ^ *pb;
95 v = v - ((v >> 1) & 0x55555555);
96 v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
97 dist += (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
108 const unsigned char *p = a.ptr<
unsigned char>();
110 for(
int i = 0; i < a.cols; ++i, ++p)
112 ss << (int)*p <<
" ";
122 a.create(1, FORB::L, CV_8U);
123 unsigned char *p = a.ptr<
unsigned char>();
126 for(
int i = 0; i < FORB::L; ++i, ++p)
132 *p = (
unsigned char)n;
139 void FORB::toMat32F(
const std::vector<TDescriptor> &descriptors,
142 if(descriptors.empty())
148 const size_t N = descriptors.size();
150 mat.create(N, FORB::L*8, CV_32F);
151 float *p = mat.ptr<
float>();
153 for(
size_t i = 0; i < N; ++i)
155 const int C = descriptors[i].cols;
156 const unsigned char *desc = descriptors[i].ptr<
unsigned char>();
158 for(
int j = 0; j < C; ++j, p += 8)
160 p[0] = (desc[j] & (1 << 7) ? 1 : 0);
161 p[1] = (desc[j] & (1 << 6) ? 1 : 0);
162 p[2] = (desc[j] & (1 << 5) ? 1 : 0);
163 p[3] = (desc[j] & (1 << 4) ? 1 : 0);
164 p[4] = (desc[j] & (1 << 3) ? 1 : 0);
165 p[5] = (desc[j] & (1 << 2) ? 1 : 0);
166 p[6] = (desc[j] & (1 << 1) ? 1 : 0);
167 p[7] = desc[j] & (1);
174 void FORB::toMat8U(
const std::vector<TDescriptor> &descriptors,
177 mat.create(descriptors.size(), 32, CV_8U);
179 unsigned char *p = mat.ptr<
unsigned char>();
181 for(
size_t i = 0; i < descriptors.size(); ++i, p += 32)
183 const unsigned char *
d = descriptors[i].ptr<
unsigned char>();
184 std::copy(d, d+32, p);
cv::Mat TDescriptor
Descriptor type.