Skip to content

Commit b1e5778

Browse files
committed
supported HF-Net
1 parent 69b74a7 commit b1e5778

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

modules/rgbd/samples/large_kinfu_LCD.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ 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 which can be download at URL=http://udel.edu/~nmerrill/calc.tar.gz.}"
62-
"{modelTxt | | Path to a .prototxt file contains the model definition of trained network.}"
63-
"{width | 160 | Preprocess input image by resizing to a specific width. It should be multiple by 32. }"
64-
"{height | 120 | Preprocess input image by resizing to a specific height. It should be multiple by 32. }"
65-
"{backend | 0 | Choose one of computation backends: "
61+
"{modelBin | | Path to a binary .bin file contains trained network which can be download at URL=https://1drv.ms/u/s!ApQBoiZSe8Evgolqw23hI8D7lP9mKw?e=ywHAc5}"
62+
"{modelTxt | | Path to a .xml file contains the model definition of trained network.}"
63+
"{width | 640 | Preprocess input image by resizing to a specific width. }"
64+
"{height | 480 | Preprocess input image by resizing to a specific height. It should be multiple by 32. }"
65+
"{backend | 2 | At current stage only openvino available, and other backend will be supported soon."
66+
" Choose one of computation backends: "
6667
"0: automatically (by default), "
6768
"1: Halide language (http://halide-lang.org/), "
6869
"2: Intel's Deep Learning Inference Engine (https://software.intel.com/openvino-toolkit), "
@@ -80,7 +81,8 @@ static const std::string message =
8081
"\nto demonstrate Submap based large environment reconstruction"
8182
"\nThis module uses the newer hashtable based TSDFVolume (relatively fast) for larger "
8283
"reconstructions by default\n"
83-
"\n The DNN model can be downdload at URL=http://udel.edu/~nmerrill/calc.tar.gz .\n";
84+
"\n The used OpenVINO DNN model can be downdload at URL=https://1drv.ms/u/s!ApQBoiZSe8Evgolqw23hI8D7lP9mKw?e=ywHAc5.\n"
85+
"\n Make sure that OpenVINO DNN backend is available.\n";
8486

8587
int main(int argc, char** argv)
8688
{

modules/rgbd/src/large_kinfu.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
323323
{
324324
// Adding Loop Edge for optimize. If the Edge is duplicate, then skip.
325325
if(submapMgr->addEdgeToCurrentSubmap(currentSubmapId, tarSubmapID))
326-
CV_LOG_INFO(NULL, "There is Loop Closure!!!! New edge was added from Submap :"<<currentSubmapId<<" to Submap:"<<tarSubmapID);
326+
CV_LOG_INFO(NULL, "LCD: Find a NEW LOOP! from Submap :"<<currentSubmapId<<" to Submap:"<<tarSubmapID);
327+
}else
328+
{
329+
CV_LOG_INFO(NULL, "LCD: No Loop.");
327330
}
328331
}
329332
}

modules/rgbd/src/loop_closure_detection.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ LoopClosureDetectionImpl::LoopClosureDetectionImpl(const String& _modelBin, cons
1919
net = makePtr<dnn::Net>(dnn::readNet(_modelBin, _modelTxt));
2020
}
2121

22+
//Only HF-Net with OpenVINO backend was supported.
23+
// Pre-trained model can be found at https://1drv.ms/u/s!ApQBoiZSe8Evgolqw23hI8D7lP9mKw?e=ywHAc5.
24+
//! TODO: HF-Net with OpenCV DNN backend.
2225
net->setPreferableBackend(_backendId);
2326
net->setPreferableTarget(_targetId);
27+
outNameDNN = net->getUnconnectedOutLayersNames();
2428

2529
KFDataBase = makePtr<KeyFrameDatabase>(maxDatabaseSize);
2630
}
@@ -115,7 +119,9 @@ bool LoopClosureDetectionImpl::loopCheck(int& tarSubmapID)
115119

116120
// find target submap ID
117121
if(bestLoopFrame->submapID == -1 || bestLoopFrame->submapID == currentSubmapID)
122+
{
118123
return false;
124+
}
119125
else
120126
{
121127
tarSubmapID = bestLoopFrame->submapID;
@@ -151,7 +157,7 @@ bool LoopClosureDetectionImpl::ORBMather(InputArray feature1, InputArray feature
151157
}
152158
if(goodMatches.size() < ORBminMathing)
153159
{
154-
CV_LOG_INFO(NULL, "Currently there are too few ORB matching pairs.");
160+
CV_LOG_INFO(NULL, "LOOP CLOSURE: There are too few ORB matching pairs.");
155161
return false;
156162
}
157163
else
@@ -207,15 +213,17 @@ void LoopClosureDetectionImpl::reset()
207213

208214
void LoopClosureDetectionImpl::processFrame(InputArray img, Mat& DNNfeature, std::vector<KeyPoint>& currentKeypoints, Mat& ORBFeature)
209215
{
216+
std::vector<Mat> outMats;
217+
210218
// DNN processing.
211219
Mat imgBlur, outDNN, outORB;
212-
cv::GaussianBlur(img, imgBlur, cv::Size(7, 7), 0);
213-
Mat blob = dnn::blobFromImage(imgBlur, 1.0/255.0, inputSize);
220+
Mat blob = dnn::blobFromImage(imgBlur, 1.0, inputSize);
221+
214222
net->setInput(blob);
215-
net->forward(outDNN);
223+
net->forward(outMats, outNameDNN);
216224

217-
outDNN /= norm(outDNN);
218-
DNNfeature = outDNN.clone();
225+
outMats[0] /= norm(outMats[0]);
226+
DNNfeature = outMats[0].clone();
219227

220228
// ORB process
221229
#ifdef HAVE_OPENCV_FEATURES2D

modules/rgbd/src/loop_closure_detection.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ class LoopClosureDetectionImpl : public LoopClosureDetection
5353
#endif
5454
size_t ORBminMathing = 10;
5555

56-
// Param: Only for DeepLCD
57-
int minDatabaseSize = 5;
56+
int minDatabaseSize = 50;
5857
int maxDatabaseSize = 2000;
5958

6059
int preLoopedKFID = -1;
6160

62-
double similarityHigh = 0.94;
63-
double similarityLow = 0.92;
61+
// Param: HF-Net
62+
// Github Link: https://github.com/ethz-asl/hfnet
63+
std::vector<String> outNameDNN;
64+
double similarityHigh = 0.64;
65+
double similarityLow = 0.60;
6466

6567
};
6668

6769
}
6870
}
69-
#endif
71+
#endif

0 commit comments

Comments
 (0)