forked from dorian3d/DBoW2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFBrief.cpp
102 lines (76 loc) · 2.2 KB
/
FBrief.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* File: FBrief.cpp
* Date: November 2011
* Author: Dorian Galvez-Lopez
* Description: functions for BRIEF descriptors
* License: see the LICENSE.txt file
*
*/
#include <vector>
#include <string>
#include <sstream>
#include "FBrief.h"
using namespace std;
namespace DBoW2 {
// --------------------------------------------------------------------------
void FBrief::meanValue(const std::vector<FBrief::pDescriptor> &descriptors,
FBrief::TDescriptor &mean)
{
mean.reset();
if(descriptors.empty()) return;
const int N2 = descriptors.size() / 2;
vector<int> counters(FBrief::L, 0);
vector<FBrief::pDescriptor>::const_iterator it;
for(it = descriptors.begin(); it != descriptors.end(); ++it)
{
const FBrief::TDescriptor &desc = **it;
for(int i = 0; i < FBrief::L; ++i)
{
if(desc[i]) counters[i]++;
}
}
for(int i = 0; i < FBrief::L; ++i)
{
if(counters[i] > N2) mean.set(i);
}
}
// --------------------------------------------------------------------------
double FBrief::distance(const FBrief::TDescriptor &a,
const FBrief::TDescriptor &b)
{
return (double)(a^b).count();
}
// --------------------------------------------------------------------------
std::string FBrief::toString(const FBrief::TDescriptor &a)
{
return a.to_string(); // reversed
}
// --------------------------------------------------------------------------
void FBrief::fromString(FBrief::TDescriptor &a, const std::string &s)
{
stringstream ss(s);
ss >> a;
}
// --------------------------------------------------------------------------
void FBrief::toMat32F(const std::vector<TDescriptor> &descriptors,
cv::Mat &mat)
{
if(descriptors.empty())
{
mat.release();
return;
}
const int N = descriptors.size();
mat.create(N, FBrief::L, CV_32F);
for(int i = 0; i < N; ++i)
{
const TDescriptor& desc = descriptors[i];
float *p = mat.ptr<float>(i);
for(int j = 0; j < FBrief::L; ++j, ++p)
{
*p = (desc[j] ? 1.f : 0.f);
}
}
}
// --------------------------------------------------------------------------
} // namespace DBoW2