Skip to content

Commit c7a7c16

Browse files
committed
bug fixed
1 parent d14c636 commit c7a7c16

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

modules/rgbd/samples/large_kinfu_LCD.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static const char* keys = {
5858
" in coarse mode points and normals are displayed }"
5959
"{idle | | Do not run LargeKinfu, just display depth frames }"
6060
"{record | | Write depth frames to specified file list (the same format as for the 'depth' key) }"
61-
"{modelBin | | Path to a binary .caffemodel file contains trained network.}"
61+
"{modelBin | | Path to a binary .caffemodel file contains trained network which can be download at URL=http://udel.edu/~nmerrill/calc.tar.gz.}"
6262
"{modelTxt | | Path to a .prototxt file contains the model definition of trained network.}"
6363
"{width | 160 | Preprocess input image by resizing to a specific width. It should be multiple by 32. }"
6464
"{height | 120 | Preprocess input image by resizing to a specific height. It should be multiple by 32. }"
@@ -79,7 +79,8 @@ static const std::string message =
7979
"\nhttps://vision.in.tum.de/data/datasets/rgbd-dataset"
8080
"\nto demonstrate Submap based large environment reconstruction"
8181
"\nThis module uses the newer hashtable based TSDFVolume (relatively fast) for larger "
82-
"reconstructions by default\n";
82+
"reconstructions by default\n"
83+
"\n The DNN model can be downdload at URL=http://udel.edu/~nmerrill/calc.tar.gz .\n";
8384

8485
int main(int argc, char** argv)
8586
{

modules/rgbd/src/large_kinfu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
323323
if(ifLoop && tarSubmapID != -1 && currentSubmapId != tarSubmapID)
324324
{
325325
// Adding Loop Edge for optimize. If the Edge is duplicate, then skip.
326-
submapMgr->addEdgeToCurrentSubmap(currentSubmapId, tarSubmapID);
327-
CV_LOG_INFO(NULL, "There is Loop Closure!!!! New edge was added.");
326+
if(submapMgr->addEdgeToCurrentSubmap(currentSubmapId, tarSubmapID))
327+
CV_LOG_INFO(NULL, "There is Loop Closure!!!! New edge was added from Submap :"<<currentSubmapId<<" to Submap:"<<tarSubmapID);
328328
}
329329
}
330330
}

modules/rgbd/src/loop_closure_detection.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "precomp.hpp"
66
#include "loop_closure_detection.hpp"
7-
7+
#include "keyframe.cpp"
88
namespace cv{
99
namespace large_kinfu{
1010

@@ -73,10 +73,24 @@ bool LoopClosureDetectionImpl::loopCheck(int& tarSubmapID)
7373
}
7474
}
7575

76+
// Remove the keyframe belonging to the currentSubmap.
77+
iter = candidateKFs.begin();
78+
while (iter != candidateKFs.end() )
79+
{
80+
Ptr<KeyFrame> keyFrameDB = KFDataBase->getKeyFrameByID(*iter);
81+
if(keyFrameDB->submapID == currentFrameID)
82+
{
83+
candidateKFs.erase(iter);
84+
}
85+
iter++;
86+
}
87+
7688
// If all candidate KF from the same submap, then return true.
7789
int tempSubmapID = -1;
7890
iter = candidateKFs.begin();
7991

92+
// If the candidate frame does not belong to the same submapID,
93+
// it means that it is impossible to specify the target SubmapID.
8094
while (iter != candidateKFs.end() ) {
8195
Ptr<KeyFrame> keyFrameDB = KFDataBase->getKeyFrameByID(*iter);
8296
if(tempSubmapID == -1)
@@ -96,21 +110,25 @@ bool LoopClosureDetectionImpl::loopCheck(int& tarSubmapID)
96110

97111
if(!candidateKFs.empty())
98112
bestLoopFrame = KFDataBase->getKeyFrameByID(candidateKFs[0]);
113+
else
114+
return false;
99115

100116
// find target submap ID
101-
if(bestLoopFrame->submapID == -1)
117+
if(bestLoopFrame->submapID == -1 || bestLoopFrame->submapID == currentSubmapID)
102118
return false;
103119
else
104120
{
105121
tarSubmapID = bestLoopFrame->submapID;
106122
preLoopedKFID = currentFrameID;
107123
currentFrameID = -1;
124+
108125
return true;
109126
}
110127
}
111128

112129
void LoopClosureDetectionImpl::addFrame(InputArray _img, const int frameID, const int submapID, int& tarSubmapID, bool& ifLoop)
113130
{
131+
114132
CV_Assert(!_img.empty());
115133
currentFrameID = frameID;
116134
currentSubmapID = submapID;
@@ -145,14 +163,16 @@ void LoopClosureDetectionImpl::reset()
145163
KFDataBase->reset();
146164
}
147165

148-
void LoopClosureDetectionImpl::processFrame(InputArray img, OutputArray output)
166+
void LoopClosureDetectionImpl::processFrame(InputArray img, Mat& output)
149167
{
150-
Mat blob = dnn::blobFromImage(img, 1.0/255.0, inputSize);
168+
Mat imgBlur, outMat;
169+
cv::GaussianBlur(img, imgBlur, cv::Size(7, 7), 0);
170+
Mat blob = dnn::blobFromImage(imgBlur, 1.0/255.0, inputSize);
151171
net->setInput(blob);
152-
net->forward(output);
172+
net->forward(outMat);
153173

154-
Mat outputFeature = output.getMat();
155-
outputFeature /= norm(outputFeature);
174+
outMat /= norm(outMat);
175+
output = outMat.clone();
156176

157177
//! Add ORB feature.
158178
}

modules/rgbd/src/loop_closure_detection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LoopClosureDetectionImpl : public LoopClosureDetection
2222

2323
void reset() CV_OVERRIDE;
2424

25-
void processFrame(InputArray img, OutputArray DNNfeature);
25+
void processFrame(InputArray img, Mat& DNNfeature);
2626

2727
bool newFrameCheck();
2828

@@ -43,7 +43,7 @@ class LoopClosureDetectionImpl : public LoopClosureDetection
4343
int preLoopedKFID = -1;
4444

4545
double similarityHigh = 0.94;
46-
double similarityLow = 0.92;
46+
double similarityLow = 0.91;
4747

4848
};
4949

modules/rgbd/src/submap.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Submap
6767
}
6868

6969
// Adding new Edge for LCD. Return true or false to indicate whether adding success.
70-
void addEdgeToSubmap(const int tarSubmapID, const Affine3f& tarPose);
70+
bool addEdgeToSubmap(const int tarSubmapID, const Affine3f& tarPose);
7171

7272
//! TODO: Possibly useless
7373
virtual void setStartFrameId(int _startFrameId) { startFrameId = _startFrameId; };
@@ -122,7 +122,7 @@ void Submap<MatType>::updatePyrPointsNormals(const int pyramidLevels)
122122
}
123123

124124
template<typename MatType>
125-
void Submap<MatType>::addEdgeToSubmap(const int tarSubmapID, const Affine3f& tarPose)
125+
bool Submap<MatType>::addEdgeToSubmap(const int tarSubmapID, const Affine3f& tarPose)
126126
{
127127
// duplicate check.
128128
auto iter = constraints.find(tarSubmapID);
@@ -136,6 +136,11 @@ void Submap<MatType>::addEdgeToSubmap(const int tarSubmapID, const Affine3f& tar
136136
// Create new Edge.
137137
PoseConstraint& preConstrain = getConstraint(tarSubmapID);
138138
preConstrain.accumulatePose(estimatePose, 1);
139+
140+
return true;
141+
} else
142+
{
143+
return false;
139144
}
140145
}
141146

@@ -187,7 +192,7 @@ class SubmapManager
187192

188193
int estimateConstraint(int fromSubmapId, int toSubmapId, int& inliers, Affine3f& inlierPose);
189194

190-
void addEdgeToCurrentSubmap(const int currentSubmapID, const int tarSubmapID);
195+
bool addEdgeToCurrentSubmap(const int currentSubmapID, const int tarSubmapID);
191196

192197
bool updateMap(int _frameId, std::vector<MatType> _framePoints, std::vector<MatType> _frameNormals);
193198

@@ -419,13 +424,12 @@ bool SubmapManager<MatType>::shouldChangeCurrSubmap(int _frameId, int toSubmapId
419424
}
420425

421426
template<typename MatType>
422-
void SubmapManager<MatType>::addEdgeToCurrentSubmap(const int currentSubmapID, const int tarSubmapID)
427+
bool SubmapManager<MatType>::addEdgeToCurrentSubmap(const int currentSubmapID, const int tarSubmapID)
423428
{
424429
Ptr<SubmapT> currentSubmap = getSubmap(currentSubmapID);
425430
Ptr<SubmapT> tarSubmap = getSubmap(tarSubmapID);
426431

427-
currentSubmap->addEdgeToSubmap(tarSubmapID, tarSubmap->pose);
428-
432+
return currentSubmap->addEdgeToSubmap(tarSubmapID, tarSubmap->pose);
429433
}
430434

431435
template<typename MatType>

0 commit comments

Comments
 (0)