-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKeyFrame.cc
213 lines (185 loc) · 5.68 KB
/
KeyFrame.cc
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright 2008 Isis Innovation Limited
#include "KeyFrame.h"
#include "ShiTomasi.h"
#include "SmallBlurryImage.h"
#include <cvd/vision.h>
#include <cvd/fast_corner.h>
namespace PTAMM {
using namespace CVD;
using namespace std;
using namespace GVars3;
/**
* Constructer.
* @param cam the camera that made this keyframe
*/
KeyFrame::KeyFrame(const ATANCamera &cam)
: pSBI( NULL ),
Camera(cam)
{
}
/**
* Destructor
*/
KeyFrame::~KeyFrame()
{
if( pSBI != NULL ) {
delete pSBI;
pSBI = NULL;
}
}
/**
* Keyframe copy constructor
* @param rhs
*/
KeyFrame::KeyFrame(const KeyFrame &rhs)
: Camera( rhs.Camera )
{
*this = rhs;
}
/**
* Keyframe assingment operater.
* Copies one keyframe from another
* @param rhs Keyframe to copy from
* @return the resulting copy
*/
KeyFrame& KeyFrame::operator=(const KeyFrame &rhs)
{
if(this == &rhs) {
return *this;
}
se3CfromW = rhs.se3CfromW;
bFixed = rhs.bFixed;
mMeasurements = rhs.mMeasurements;
dSceneDepthMean = rhs.dSceneDepthMean;
dSceneDepthSigma = rhs.dSceneDepthSigma;
Camera = rhs.Camera;
for( int i = 0; i < LEVELS; ++i ) {
aLevels[i] = rhs.aLevels[i];
}
//should actually copy this, but is cheap to make.
if( rhs.pSBI ) {
pSBI = new SmallBlurryImage(rhs);
}
else {
pSBI = NULL;
}
return *this;
}
/**
* Perpares a Keyframe from an image. Generates pyramid levels, does FAST detection, etc.
* Does not fully populate the keyframe struct, but only does the bits needed for the tracker;
* e.g. does not perform FAST nonmax suppression. Things like that which are needed by the
* mapmaker but not the tracker go in MakeKeyFrame_Rest();
* @param im image to make keyframe from
*/
void KeyFrame::MakeKeyFrame_Lite(BasicImage<CVD::byte> &im)
{
// First, copy out the image data to the pyramid's zero level.
aLevels[0].im.resize(im.size());
copy(im, aLevels[0].im);
// Then, for each level...
for(int i=0; i<LEVELS; i++)
{
Level &lev = aLevels[i];
if(i!=0)
{ // .. make a half-size image from the previous level..
lev.im.resize(aLevels[i-1].im.size() / 2);
halfSample(aLevels[i-1].im, lev.im);
}
// .. and detect and store FAST corner points.
// I use a different threshold on each level; this is a bit of a hack
// whose aim is to balance the different levels' relative feature densities.
lev.vCorners.clear();
lev.vCandidates.clear();
lev.vMaxCorners.clear();
if(i == 0)
fast_corner_detect_10(lev.im, lev.vCorners, 10);
if(i == 1)
fast_corner_detect_10(lev.im, lev.vCorners, 15);
if(i == 2)
fast_corner_detect_10(lev.im, lev.vCorners, 15);
if(i == 3)
fast_corner_detect_10(lev.im, lev.vCorners, 10);
// Generate row look-up-table for the FAST corner points: this speeds up
// finding close-by corner points later on.
unsigned int v=0;
lev.vCornerRowLUT.clear();
for(int y=0; y<lev.im.size().y; y++)
{
while( (v < lev.vCorners.size()) && (y > lev.vCorners[v].y) )
v++;
lev.vCornerRowLUT.push_back(v);
}
}
}
/**
* Fills the rest of the keyframe structure needed by the mapmaker:
* FAST nonmax suppression, generation of the list of candidates for further map points,
* creation of the relocaliser's SmallBlurryImage.
*/
void KeyFrame::MakeKeyFrame_Rest()
{
static gvar3<double> gvdCandidateMinSTScore("MapMaker.CandidateMinShiTomasiScore", 70, SILENT);
// For each level...
for(int l=0; l<LEVELS; l++)
{
Level &lev = aLevels[l];
// .. find those FAST corners which are maximal..
fast_nonmax(lev.im, lev.vCorners, 10, lev.vMaxCorners);
// .. and then calculate the Shi-Tomasi scores of those, and keep the ones with
// a suitably high score as Candidates, i.e. points which the mapmaker will attempt
// to make new map points out of.
for(vector<ImageRef>::iterator i=lev.vMaxCorners.begin(); i!=lev.vMaxCorners.end(); i++)
{
if(!lev.im.in_image_with_border(*i, 10))
continue;
double dSTScore = FindShiTomasiScoreAtPoint(lev.im, 3, *i);
if(dSTScore > *gvdCandidateMinSTScore)
{
Candidate c;
c.irLevelPos = *i;
c.dSTScore = dSTScore;
lev.vCandidates.push_back(c);
}
}
}
// Also, make a SmallBlurryImage of the keyframe: The relocaliser uses these.
pSBI = new SmallBlurryImage(*this);
// Relocaliser also wants the jacobians..
pSBI->MakeJacs();
}
/**
* Level needs its own operator= to override CVD's reference-counting behaviour.
* @param rhs the level to copy
* @return the copied level
*/
Level& Level::operator=(const Level &rhs)
{
// Operator= should physically copy pixels, not use CVD's reference-counting image copy.
im.resize(rhs.im.size());
copy(rhs.im, im);
vCorners = rhs.vCorners;
vMaxCorners = rhs.vMaxCorners;
vCornerRowLUT = rhs.vCornerRowLUT;
return *this;
}
// -------------------------------------------------------------
// Some useful globals defined in LevelHelpers.h live here:
Vector<3> gavLevelColors[LEVELS];
// These globals are filled in here. A single static instance of this struct is run before main()
struct LevelHelpersFiller // Code which should be initialised on init goes here; this runs before main()
{
LevelHelpersFiller()
{
for(int i=0; i<LEVELS; i++)
{
if(i==0) gavLevelColors[i] = makeVector( 1.0, 0.0, 0.0);
else if(i==1) gavLevelColors[i] = makeVector( 1.0, 1.0, 0.0);
else if(i==2) gavLevelColors[i] = makeVector( 0.0, 1.0, 0.0);
else if(i==3) gavLevelColors[i] = makeVector( 0.0, 0.0, 0.7);
else gavLevelColors[i] = makeVector( 1.0, 1.0, 0.7); // In case I ever run with LEVELS > 4
}
}
};
static LevelHelpersFiller foo;
}