-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for SURF Features #739
base: develop
Are you sure you want to change the base?
Changes from 250 commits
7c3dbb8
7c2cd4b
a5e3f20
8c99469
709e7fa
2b0f12a
21f70c8
7171892
9e47d6c
6751a87
72fe9ab
097d25e
b994706
be3f540
ef98f66
c636187
63a0c1d
a600e1f
951f71e
736933f
155a967
13be2a3
024adfe
f6fca88
282e0d3
f29950a
d0634f5
d3b5579
3c07f04
053b5a4
665c330
f09c9da
d449b11
35ac3d7
8dffea4
a2fb82b
7319ebe
7313820
65dd021
0371bb9
699f576
7e57124
8a7d1bf
e208f80
84e481e
c4afb0f
043a0b2
12bc19d
4d5d9a4
27d1ff6
2df6e72
0389e2d
d51791f
64c821a
8b2ae7d
664109d
bd434d9
7b85f07
6af1a5d
670a353
3672ec0
bbb382b
8e5564e
2b028f4
e7aa693
dd80beb
e2eb015
3b5469d
b9d8b4d
e76a964
f9e51ea
4ae7844
73e635f
5175020
0e361ec
f82780a
479fb6c
5e49689
8706c4f
bb369ab
eddf417
e1af858
81d0636
dc138d9
2dd4568
6f9a847
ab86851
fc665e8
ae9cedf
6724466
7fc86ce
1bf3b58
a559a1b
3b85e29
0b45697
52f9ffd
cf97193
b6f77db
1d44468
32d1c5c
1b5fcee
37200ce
a1cb93b
b722295
0bdc3f4
fa32561
094c6a3
05e7647
289d17a
1f19133
02090cc
16b6935
1be1364
2c63429
dad30da
95056f4
515f3cc
9259f3e
8f10e3e
5434e47
0b4278d
e11f84b
2c2500c
5c7893a
57029a9
b8f3a89
ef06738
be88434
16365e9
ad7b45c
adee667
770f701
947a5f8
8b21d28
4f105f9
adddbd4
1b17367
575acd3
908cba2
7aa76d5
ccf8f4a
0d55a90
62f202a
403e412
d29c4ae
7b3b7aa
15f3a4c
c4f0a7f
4fcc527
ce7e93c
64b6737
94e0295
13e9f8a
1d8d034
99e7e02
f1d961d
4e09cc4
0afffd5
b006474
7e86341
f42f0a7
752d83b
2c6d82e
aca22c1
0a3a78f
c930cf4
fc0f6d2
78e5352
eb83eaf
996b1cd
0b7cf9f
d90a790
0c365a5
5019d3c
968a3cb
f5fe320
b7c59d0
fa097da
f7ef637
0155e57
16f7389
2c959e0
7be4288
70a2242
536ddda
9b0d1a6
e23750c
2d2014f
59dc31b
6c161f5
c98948d
c1cfc85
82ef6c1
9854315
08ad398
38e6b10
2327d4d
0719a5a
81c1645
751a906
37da508
c008ddf
0840c04
a06e512
2319b44
493c9b2
2c1fe82
1be0584
957dbc3
efac5a3
b7b2fae
69a0cd5
3be4eea
d20b3f3
f248d71
c1d2fc9
7447d77
37af82b
2bc9d7f
a40f985
53d5785
3e344de
b955875
ee63c16
d126a27
61c1bab
dd4d52b
9260515
8bf3289
2072511
00d6f13
8d296f6
6bc17c4
3ecb058
419170a
8dfd89e
6e8005d
52b2930
f07f790
575e15f
bf83e17
e44d315
2a73a2f
d86a9f1
0794281
79188f2
dea2d53
9747f3c
e7002db
4f7324e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
// same settings! | ||
// TODO(oalexan1): Ideally the settings used here must be saved in the | ||
// map file, for the localize executable to read them from there. | ||
DEFINE_bool(verbose, false, | ||
"If true, print out information about the localization process."); | ||
DEFINE_int32(hamming_distance, 90, | ||
"A smaller value keeps fewer but more reliable binary descriptor matches."); | ||
DEFINE_double(goodness_ratio, 0.8, | ||
|
@@ -50,7 +52,7 @@ DEFINE_int32(max_surf_features, 5000, | |
"Maximum number of features to be computed using SURF."); | ||
DEFINE_double(min_surf_threshold, 1.1, | ||
"Minimum threshold for feature detection using SURF."); | ||
DEFINE_double(default_surf_threshold, 10, | ||
DEFINE_double(default_surf_threshold, 400, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably make sure this doesn't adversely affect mapping |
||
"Default threshold for feature detection using SURF."); | ||
DEFINE_double(max_surf_threshold, 1000, | ||
"Maximum threshold for feature detection using SURF."); | ||
|
@@ -99,6 +101,16 @@ namespace interest_point { | |
else | ||
break; | ||
} | ||
if (FLAGS_verbose) { | ||
if (keypoints->size() < min_features_) | ||
LOG(WARNING) << "Max retries reached. Found " << keypoints->size() | ||
<< " keypoints which is less than min of " << min_features_ | ||
<< " keypoints. Consider decreasing the default threshold."; | ||
else if (keypoints->size() > max_features_) | ||
LOG(WARNING) << "Max retries reached. Found " << keypoints->size() | ||
<< " keypoints which exeeds max of " << max_features_ | ||
<< " keypoints. Consider increasing the default threshold."; | ||
} | ||
ComputeImpl(image, keypoints, keypoints_description); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2017, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* | ||
* All rights reserved. | ||
* | ||
* The Astrobee platform is licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef SPARSE_MAPPING_BRISK_IMAGE_DATABASE_H_ | ||
#define SPARSE_MAPPING_BRISK_IMAGE_DATABASE_H_ | ||
|
||
#include <sparse_map/FBrisk.h> | ||
#include <sparse_map/templated_image_database.h> | ||
|
||
namespace sparse_mapping { | ||
using BriskImageDatabase = TemplatedImageDatabase<DBoW2::FBrisk::TDescriptor, DBoW2::FBrisk>; | ||
} // namespace sparse_mapping | ||
#endif // SPARSE_MAPPING_BRISK_IMAGE_DATABASE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Copyright (c) 2017, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* | ||
* All rights reserved. | ||
* | ||
* The Astrobee platform is licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef SPARSE_MAPPING_IMAGE_DATABASE_H_ | ||
#define SPARSE_MAPPING_IMAGE_DATABASE_H_ | ||
|
||
#include <google/protobuf/io/zero_copy_stream_impl.h> | ||
|
||
#include <vector> | ||
|
||
namespace sparse_mapping { | ||
class ImageDatabase { | ||
public: | ||
virtual ~ImageDatabase() {} | ||
virtual std::vector<int> Query(const Descriptors& descriptors, const int max_results) = 0; | ||
virtual void SaveProtobuf(google::protobuf::io::ZeroCopyOutputStream* output) const = 0; | ||
virtual void LoadProtobuf(google::protobuf::io::ZeroCopyInputStream* input, int db_type) = 0; | ||
}; | ||
} // namespace sparse_mapping | ||
#endif // SPARSE_MAPPING_IMAGE_DATABASE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2017, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* | ||
* All rights reserved. | ||
* | ||
* The Astrobee platform is licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef SPARSE_MAPPING_SURF_IMAGE_DATABASE_H_ | ||
#define SPARSE_MAPPING_SURF_IMAGE_DATABASE_H_ | ||
|
||
#include <sparse_map/templated_image_database.h> | ||
|
||
namespace sparse_mapping { | ||
// TODO(rsoussan): Make sure we use surf 64!!! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this todo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember haha, probably not |
||
using SurfImageDatabase = TemplatedImageDatabase<DBoW2::FSurf64::TDescriptor, DBoW2::FSurf64>; | ||
} // namespace sparse_mapping | ||
#endif // SPARSE_MAPPING_SURF_IMAGE_DATABASE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Copyright (c) 2017, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* | ||
* All rights reserved. | ||
* | ||
* The Astrobee platform is licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_H_ | ||
#define SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_H_ | ||
|
||
#include <sparse_map/image_database.h> | ||
#include <sparse_map/image_database_params.h> | ||
#include <sparse_map/templated_feature_vocabulary.h> | ||
|
||
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" | ||
#pragma GCC diagnostic push | ||
#include <DBoW2/DBoW2.h> | ||
#pragma GCC diagnostic pop | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
namespace sparse_mapping { | ||
|
||
template <class TDescriptor, class F> | ||
class TemplatedImageDatabase : public DBoW2::TemplatedDatabase<TDescriptor, F>, public ImageDatabase { | ||
public: | ||
TemplatedImageDatabase(const TemplatedFeatureVocabulary<TDescriptor, F>& voc, const ImageDatabaseParams& params); | ||
TemplatedImageDatabase(const DescriptorsSet& descriptors_set, const ImageDatabaseParams& params); | ||
// Return the cids of the images which are most similar to the current image in sorted order | ||
// beginning with the best matching cids | ||
std::vector<int> Query(const Descriptors& descriptors, const int max_results) const override; | ||
|
||
// Protobuf Functions | ||
explicit TemplatedImageDatabase(google::protobuf::io::ZeroCopyInputStream* input); | ||
void SaveProtobuf(google::protobuf::io::ZeroCopyOutputStream* output) const override; | ||
void LoadProtobuf(google::protobuf::io::ZeroCopyInputStream* input) override; | ||
}; | ||
|
||
// Implementation | ||
template <class TDescriptor, class F> | ||
TemplatedImageDatabase<TDescriptor, F>::TemplatedImageDatabase( | ||
TemplatedFeatureVocabulary<TDescriptor, F> const& vocabulary, const ImageDatabaseParams& params) | ||
: DBoW2::TemplatedDatabase<TDescriptor, F>(vocabulary, params.use_direct_index, params.direct_index_levels) {} | ||
|
||
template <class TDescriptor, class F> | ||
TemplatedImageDatabase<TDescriptor, F>::TemplatedImageDatabase(const DescriptorsSet& descriptors_set, | ||
const ImageDatabaseParams& params) | ||
: DBoW2::TemplatedDatabase<TDescriptor, F>(params.use_direct_index, params.direct_index_levels) { | ||
const TemplatedFeatureVocabulary<TDescriptor, F> vocabulary(descriptors_set, params.vocabulary); | ||
setVocabulary(vocabulary); | ||
for (const auto& descriptors : descriptors_set) { | ||
add(descriptors); | ||
} | ||
} | ||
|
||
template <class TDescriptor, class F> | ||
std::vector<int> TemplatedImageDatabase<TDescriptor, F>::Query(const Descriptors& descriptors, const int max_results) { | ||
std::vector<int> matching_cids; | ||
DBoW2::QueryResults results; | ||
this->query(descriptors, results, max_results); | ||
for (const auto& result : results) { | ||
matching_cids.push_back(result.Id); | ||
} | ||
return matching_cids; | ||
} | ||
} // namespace sparse_mapping | ||
#endif // SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_H_ | ||
|
||
#include <sparse_mapping/templated_image_database_protobuf.h> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* Copyright (c) 2017, United States Government, as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* | ||
* All rights reserved. | ||
* | ||
* The Astrobee platform is licensed under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#ifndef SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_PROTOBUF_H_ | ||
#define SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_PROTOBUF_H_ | ||
|
||
#include <sparse_map.pb.h> | ||
#include <google/protobuf/io/zero_copy_stream_impl.h> | ||
|
||
// Implementation | ||
template <class TDescriptor, class F> | ||
TemplatedImageDatabase<TDescriptor, F>::TemplatedImageDatabase(google::protobuf::io::ZeroCopyInputStream* input) | ||
: DBoW2::TemplatedDatabase<TDescriptor, F>() { | ||
LoadProtobuf(input); | ||
} | ||
|
||
template <class TDescriptor, class F> | ||
void TemplatedImageDatabase<TDescriptor, F>::LoadProtobuf(google::protobuf::io::ZeroCopyInputStream* input) { | ||
TemplatedFeatureVocabulary<TDescriptor, F>* voc = new TemplatedFeatureVocabulary<TDescriptor, F>(); | ||
voc->LoadProtobuf(input); | ||
this->m_voc = voc; | ||
|
||
sparse_mapping_protobuf::DBoWDB db; | ||
|
||
if (!ReadProtobufFrom(input, &db)) { | ||
LOG(FATAL) << "Failed to parse db file."; | ||
} | ||
|
||
this->clear(); // resizes inverted file | ||
|
||
this->m_nentries = db.num_entries(); | ||
this->m_use_di = 0; | ||
this->m_dilevels = 0; | ||
|
||
for (int i = 0; i < db.num_inverted_index(); ++i) { | ||
sparse_mapping_protobuf::DBoWInvertedIndexEntry entry; | ||
if (!ReadProtobufFrom(input, &entry)) { | ||
LOG(FATAL) << "Failed to parse index entry."; | ||
} | ||
DBoW2::WordId wid = entry.word_id(); | ||
DBoW2::EntryId eid = entry.entry_id(); | ||
DBoW2::WordValue v = entry.weight(); | ||
|
||
this->m_ifile[wid].push_back(typename DBoW2::TemplatedDatabase<TDescriptor, F>::IFPair(eid, v)); | ||
} | ||
} | ||
|
||
template <class TDescriptor, class F> | ||
void TemplatedImageDatabase<TDescriptor, F>::SaveProtobuf(google::protobuf::io::ZeroCopyOutputStream* output) const { | ||
(dynamic_cast<TemplatedFeatureVocabulary<TDescriptor, F>*>(this->m_voc))->SaveProtobuf(output); | ||
|
||
sparse_mapping_protobuf::DBoWDB db; | ||
|
||
db.set_num_entries(this->m_nentries); | ||
|
||
int num_inverted_index = 0; | ||
typename DBoW2::TemplatedDatabase<TDescriptor, F>::InvertedFile::const_iterator iit; | ||
for (iit = this->m_ifile.begin(); iit != this->m_ifile.end(); ++iit) num_inverted_index += (*iit).size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be changed to a range loop? (for (const auto& ifile: m_ifile) |
||
db.set_num_inverted_index(num_inverted_index); | ||
if (!WriteProtobufTo(db, output)) { | ||
LOG(FATAL) << "Failed to write db to file."; | ||
} | ||
typename DBoW2::TemplatedDatabase<TDescriptor, F>::IFRow::const_iterator irit; | ||
int word_id = 0; | ||
for (iit = this->m_ifile.begin(); iit != this->m_ifile.end(); ++iit) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (range loop for these?) |
||
for (irit = iit->begin(); irit != iit->end(); ++irit) { | ||
sparse_mapping_protobuf::DBoWInvertedIndexEntry index; | ||
index.set_word_id(word_id); | ||
index.set_entry_id(irit->entry_id); | ||
index.set_weight(irit->word_weight); | ||
if (!WriteProtobufTo(index, output)) { | ||
LOG(FATAL) << "Failed to write db index entry to file."; | ||
} | ||
} | ||
word_id++; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not important but prefer ++x over x++, x++ adds a tmp variable and is a little slower (probably compiled out here though) |
||
} | ||
} | ||
} // namespace sparse_mapping | ||
#endif // SPARSE_MAPPING_TEMPLATED_IMAGE_DATABASE_PROTOBUF_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import rosbag | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might not know about rosbag filter, with that do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops didn't mean for that to be part of the commit. It was just more convenient for me than rosbag filter |
||
import sys | ||
|
||
if len(sys.argv) < 3: | ||
print("Usage: python copy_bag_topics.py <input_bag> <output_bag>") | ||
sys.exit(1) | ||
|
||
input_bag = sys.argv[1] | ||
output_bag = sys.argv[2] | ||
|
||
with rosbag.Bag(output_bag, 'a') as outbag: | ||
for topic, msg, t in rosbag.Bag(input_bag).read_messages(): | ||
outbag.write(topic, msg, t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be here?