Skip to content
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

Updated Map Matching With TEBLID and CLAHE #797

Merged
merged 63 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f81f78b
added hash sift as interest point
rsoussan Jun 11, 2024
b547324
added bad feature detector
rsoussan Jun 14, 2024
15096a0
added clahe instead of normal histogram equalization
rsoussan Jun 14, 2024
c87ad53
removed hashsift, made localize a member fcn
rsoussan Jun 21, 2024
7c2a29a
removed hashsift
rsoussan Jun 21, 2024
1995c80
removed old localize call
rsoussan Jun 21, 2024
a5ea253
added clahe to saving map, made optional
rsoussan Jun 22, 2024
74a8a13
added viz utils to sparse map
rsoussan Jun 22, 2024
7911ee9
added option to visualize matches during loc
rsoussan Jun 22, 2024
4574ea8
changed binary interest feature matching
rsoussan Jun 23, 2024
ec0bec4
removed config paths from map matcher
rsoussan Jun 23, 2024
5d49bb7
added option to check essential matrix
rsoussan Jun 23, 2024
c8cf520
added check for inlier matches
rsoussan Jun 23, 2024
1cedb9d
added size check for matches
rsoussan Jun 23, 2024
64c9b70
added connectivity check
rsoussan Jun 23, 2024
f8f142d
bug fixes
rsoussan Jun 23, 2024
d66da2c
added image for localization for debugging
rsoussan Jun 23, 2024
9c84220
added loading keypoints
rsoussan Jun 23, 2024
807fed3
fixed saving and loading use clahe
rsoussan Jun 24, 2024
1d98bd7
added more verbose loc printing
rsoussan Jun 24, 2024
76eec3d
updated values
rsoussan Jun 24, 2024
fb8270e
updated loc config vals
rsoussan Jun 24, 2024
04584a8
updated brisk thresh
rsoussan Jun 24, 2024
b194b86
fixed hamming threshold
rsoussan Jun 24, 2024
b59c3ac
increased min features
rsoussan Jun 24, 2024
9f97542
added check for best previous cid, added inserting similar images in …
rsoussan Jun 24, 2024
86987f9
fixed bug for best previous cid
rsoussan Jun 24, 2024
85dbf82
updated default brisk threshold
rsoussan Jun 24, 2024
b10fd2b
tuned vals
rsoussan Jun 24, 2024
3bb9088
fixed avoid adding loading keypoints when in localization mode
rsoussan Jun 24, 2024
15717de
added loc params, added different params for brisk vs. teblid
rsoussan Jun 25, 2024
a723095
fixed hamming and goodness types
rsoussan Jun 25, 2024
52905d7
fixed reading loc node params
rsoussan Jun 25, 2024
f014725
fixed camera config path
rsoussan Jun 25, 2024
ea0fc5e
added hamming and goodness to find matches call, added loading clahe …
rsoussan Jun 25, 2024
69cb35e
added clahe param check
rsoussan Jun 25, 2024
a154593
fix clahe check
rsoussan Jun 25, 2024
d42aa07
fixed clahe param in loc config
rsoussan Jun 25, 2024
ec8533a
fixed teblid use clahe value
rsoussan Jun 25, 2024
1a796d8
added loading keypoint map
rsoussan Jun 25, 2024
a84ac11
Avoid multithread histogram equalization
rsoussan Jun 25, 2024
47004ca
added support for teblid512 and teblid256
rsoussan Jun 25, 2024
c973991
added separete fcn to load keypoints
rsoussan Jun 26, 2024
ad69913
fix linters
marinagmoreira Jun 26, 2024
2a7aef3
added essential ransac iterations as params
rsoussan Jun 26, 2024
29adb0e
added returning scores in querydb call
rsoussan Jun 26, 2024
f34d0d3
added check for query score ratio
rsoussan Jun 27, 2024
ccfc15b
Merge branch 'develop' of https://github.com/nasa/astrobee into hash_…
marinagmoreira Jun 27, 2024
741d9f1
added dynamic threshold adjusting based on success rates
rsoussan Jun 27, 2024
73b7730
Merge branch 'hash_surf_and_teblib_interest_points' of https://github…
rsoussan Jun 27, 2024
f2985ec
adjusted params
rsoussan Jun 27, 2024
394f156
updated loc config
rsoussan Jun 27, 2024
179f31e
adjusted teblid dyn thresholds
rsoussan Jun 27, 2024
773b21a
added check for feature counts to dynamic thresholding
rsoussan Jun 27, 2024
7fea5db
updated loc configs
rsoussan Jun 27, 2024
06cfafa
added dynamic hamming distance option
rsoussan Jun 27, 2024
29ef6ec
some test fixes
rsoussan Jun 28, 2024
1fcaa8c
more sparse map test fixes
rsoussan Jun 28, 2024
1e05d86
fixed test db
rsoussan Jun 28, 2024
ad8fd0d
more test fixes
rsoussan Jun 28, 2024
0014e89
added enum for hist equalization type, added more info to bad headers
rsoussan Jun 28, 2024
7e9aeac
updated loc analysis scripts to use teblid
rsoussan Jun 29, 2024
bf1e0fb
converted make brisk map to make teblid map
rsoussan Jun 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 97 additions & 12 deletions astrobee/config/localization.config
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,102 @@
-- License for the specific language governing permissions and limitations
-- under the License.

num_similar = 20
ransac_inlier_tolerance = 5
ransac_iterations = 100
early_break_landmarks = 100
histogram_equalization = 1
min_features = 200
max_features = 800
detection_retries = 1
num_threads = 1
min_brisk_threshold = 20.0
default_brisk_threshold = 90.0
max_brisk_threshold = 110.0
matched_features_on = false
all_features_on = false
num_threads = 1
verbose_localization = false
visualize_localization_matches = false

-- BRISK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are BRISK and TEBLID the only choices? What about SURF? What about TEBLID256 vs. TEBLID512? (It's ok if this file isn't merged in its final form because we can tune it after the ISAAC16 code freeze. But it might help to list the available feature types at the top of the file even if we don't define parameters for all the types yet. Also, not sure about this, but it might make sense to define a default value for each parameter that applies across all feature types while enabling a feature-type-specific value to override that.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added teblid512 and teblid256, we don't really support SURF for loc since we never merged the vocab branch so I'll leave that out

brisk_num_similar = 20
brisk_min_query_score_ratio = 0
brisk_ransac_inlier_tolerance = 5
brisk_num_ransac_iterations = 100
brisk_early_break_landmarks = 100
brisk_histogram_equalization = 1
brisk_check_essential_matrix = false
brisk_essential_ransac_iterations = 2000
brisk_add_similar_images = false
brisk_add_best_previous_image = false
brisk_hamming_distance = 90
brisk_goodness_ratio = 0.8
brisk_use_clahe = false
brisk_num_extra_localization_db_images = 0
-- Detection Params
brisk_min_threshold = 20.0
brisk_default_threshold = 90.0
brisk_max_threshold = 110.0
brisk_min_features = 200
brisk_max_features = 800
brisk_detection_retries = 1
-- Localizer Threshold Params
brisk_success_history_size = 10
brisk_min_success_rate = 0
brisk_max_success_rate = 1
brisk_adjust_hamming_distance = false
brisk_min_hamming_distance = 90
brisk_max_hamming_distance = 90

-- TEBLID512
teblid512_num_similar = 20
teblid512_min_query_score_ratio = 0.45
teblid512_ransac_inlier_tolerance = 3
teblid512_num_ransac_iterations = 1000
teblid512_early_break_landmarks = 100
teblid512_histogram_equalization = 3
teblid512_check_essential_matrix = true
teblid512_essential_ransac_iterations = 2000
teblid512_add_similar_images = true
teblid512_add_best_previous_image = true
teblid512_hamming_distance = 85
teblid512_goodness_ratio = 0.8
teblid512_use_clahe = true
teblid512_num_extra_localization_db_images = 0

-- Detection Params
teblid512_min_threshold = 20.0
teblid512_default_threshold = 60.0
teblid512_max_threshold = 110.0
teblid512_min_features = 1000
teblid512_max_features = 3000
teblid512_detection_retries = 1

-- Localizer Threshold Params
teblid512_success_history_size = 10
teblid512_min_success_rate = 0.3
teblid512_max_success_rate = 0.9
teblid512_adjust_hamming_distance = false
teblid512_min_hamming_distance = 85
teblid512_max_hamming_distance = 85

-- TEBLID256
teblid256_num_similar = 20
teblid256_min_query_score_ratio = 0.45
teblid256_ransac_inlier_tolerance = 3
teblid256_num_ransac_iterations = 1000
teblid256_early_break_landmarks = 100
teblid256_histogram_equalization = 3
teblid256_check_essential_matrix = true
teblid256_essential_ransac_iterations = 2000
teblid256_add_similar_images = true
teblid256_add_best_previous_image = true
teblid256_hamming_distance = 85
teblid256_goodness_ratio = 0.8
teblid256_use_clahe = true
teblid256_num_extra_localization_db_images = 0

-- Detection Params
teblid256_min_threshold = 20.0
teblid256_default_threshold = 60.0
teblid256_max_threshold = 110.0
teblid256_min_features = 1000
teblid256_max_features = 3000
teblid256_detection_retries = 1

-- Localizer Threshold Params
teblid256_success_history_size = 10
teblid256_min_success_rate = 0.3
teblid256_max_success_rate = 0.9
teblid256_adjust_hamming_distance = false
teblid256_min_hamming_distance = 85
teblid256_max_hamming_distance = 85
1 change: 1 addition & 0 deletions localization/interest_point/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_library(interest_point
src/brisk.cc
src/essential.cc
src/matching.cc
src/BAD.cpp
)
add_dependencies(interest_point ${catkin_EXPORTED_TARGETS})
target_link_libraries(interest_point ${OPENMVG_LIBRARIES} ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
Expand Down
104 changes: 104 additions & 0 deletions localization/interest_point/include/interest_point/BAD.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @copyright 2021 Xoan Iago Suarez Canosa. All rights reserved.
* Constact: [email protected]
* Software developed in the PhD: Low-level vision for resource-limited devices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what license?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and does this really need to be included instead of linked to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* Repo link: https://github.com/iago-suarez/efficient-descriptors
* License: Apache 2
* TODO(rsoussan): Remove this and BAD.cpp and switch to opencv TEBLID if opencv
* version upgraded.
*/

#ifndef INTEREST_POINT_BAD_H_
#define INTEREST_POINT_BAD_H_

#include <opencv2/opencv.hpp>

#include <vector>
#include <string>

namespace upm {

/**
* Implementation of the Box Average Difference (BAD) descriptor. The method uses features
* computed from the difference of the average gray values of two boxes in the patch.
*
* Each pair of boxes is represented with a BoxPairParams struct. After obtaining the feature
* from them, the i'th feature is thresholded with thresholds_[i], producing the binary
* weak-descriptor.
*/
class BAD : public cv::Feature2D {
public:
/**
* @brief Descriptor number of bits, each bit is a weak-descriptor.
* The user can choose between 512 or 256 bits.
*/
enum BadSize {
SIZE_512_BITS = 100, SIZE_256_BITS = 101,
};

/**
* @param scale_factor Adjust the sampling window around detected keypoints:
- <b> 1.00f </b> should be the scale for ORB keypoints
- <b> 6.75f </b> should be the scale for SIFT detected keypoints
- <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
- <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
* @param n_bits Determine the number of bits in the descriptor. Should be either
BAD::SIZE_512_BITS or BAD::SIZE_256_BITS.
*/
explicit BAD(float scale_factor = 1.0f, BadSize n_bits = SIZE_512_BITS);

/**
* @brief Creates the BAD descriptor.
* @param scale_factor Adjust the sampling window around detected keypoints:
- <b> 1.00f </b> should be the scale for ORB keypoints
- <b> 6.75f </b> should be the scale for SIFT detected keypoints
- <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
- <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
* @param n_bits
* @return
*/
static cv::Ptr<BAD> create(float scale_factor = 1.0f, BadSize n_bits = SIZE_512_BITS) {
return cv::makePtr<upm::BAD>(scale_factor, n_bits);
}

/** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set
(second variant).

@param image Image.
@param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
with several dominant orientations (for each orientation).
@param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
descriptor for keypoint j-th keypoint.
*/
void compute(cv::InputArray image,
CV_OUT CV_IN_OUT std::vector<cv::KeyPoint> &keypoints,
cv::OutputArray descriptors) override;

int descriptorSize() const override { return box_params_.size() / 8; }
int descriptorType() const override { return CV_8UC1; }
int defaultNorm() const override { return cv::NORM_HAMMING; }
bool empty() const override { return false; }

cv::String getDefaultName() const override { return std::string("BAD") + std::to_string(box_params_.size()); }

// Struct representing a pair of boxes in the patch
struct BoxPairParams {
int x1, x2, y1, y2, boxRadius;
};

protected:
// Computes the BADdescriptor
void computeBAD(const cv::Mat &integral_img,
const std::vector<cv::KeyPoint> &keypoints,
cv::Mat &descriptors);

std::vector<float> thresholds_;
std::vector<BoxPairParams> box_params_;
float scale_factor_ = 1;
cv::Size patch_size_ = {32, 32};
};

} // namespace upm
#endif // INTEREST_POINT_BAD_H_
25 changes: 10 additions & 15 deletions localization/interest_point/include/interest_point/essential.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@ namespace interest_point {

// Performs a robust, ransac, solving for the essential matrix
// between interest point measurements in x1 and x2.
bool RobustEssential(Eigen::Matrix3d const& k1, Eigen::Matrix3d const& k2,
Eigen::Matrix2Xd const& x1, Eigen::Matrix2Xd const& x2,
Eigen::Matrix3d * e,
std::vector<size_t> * vec_inliers,
std::pair<size_t, size_t> const& size1,
std::pair<size_t, size_t> const& size2,
double * error_max,
double precision);
bool RobustEssential(Eigen::Matrix3d const& k1, Eigen::Matrix3d const& k2, Eigen::Matrix2Xd const& x1,
Eigen::Matrix2Xd const& x2, Eigen::Matrix3d* e, std::vector<size_t>* vec_inliers,
std::pair<size_t, size_t> const& size1, std::pair<size_t, size_t> const& size2, double* error_max,
double precision, const int ransac_iterations = 4096);

// Solves for the RT (Rotation and Translation) from the essential
// matrix and x1 and x2. There are 4 possible, and this returns the
// best of the 4 solutions.
bool EstimateRTFromE(Eigen::Matrix3d const& k1, Eigen::Matrix3d const& k2,
Eigen::Matrix2Xd const& x1, Eigen::Matrix2Xd const& x2,
Eigen::Matrix3d const& e, std::vector<size_t> const& vec_inliers,
Eigen::Matrix3d * r, Eigen::Vector3d * t);
// Solves for the RT (Rotation and Translation) from the essential
// matrix and x1 and x2. There are 4 possible, and this returns the
// best of the 4 solutions.
bool EstimateRTFromE(Eigen::Matrix3d const& k1, Eigen::Matrix3d const& k2, Eigen::Matrix2Xd const& x1,
Eigen::Matrix2Xd const& x2, Eigen::Matrix3d const& e, std::vector<size_t> const& vec_inliers,
Eigen::Matrix3d* r, Eigen::Vector3d* t);

} // end namespace interest_point

Expand Down
14 changes: 11 additions & 3 deletions localization/interest_point/include/interest_point/matching.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef INTEREST_POINT_MATCHING_H_
#define INTEREST_POINT_MATCHING_H_

#include <boost/optional.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <Eigen/Core>

Expand Down Expand Up @@ -45,9 +46,12 @@ namespace interest_point {
void GetDetectorParams(int & min_features, int & max_features, int & max_retries,
double & min_thresh, double & default_thresh, double & max_thresh);

int last_keypoint_count(void) { return last_keypoint_count_; }

protected:
unsigned int min_features_, max_features_, max_retries_;
double min_thresh_, default_thresh_, max_thresh_, dynamic_thresh_;
int last_keypoint_count_;
};

class FeatureDetector {
Expand Down Expand Up @@ -81,16 +85,20 @@ namespace interest_point {
friend bool operator== (FeatureDetector const& A, FeatureDetector const& B) {
return (A.detector_name_ == B.detector_name_);
}

DynamicDetector& dynamic_detector() { return *detector_; }
};

/**
* descriptor is what opencv descriptor was used to make the descriptors
* the descriptor maps are the features in the two images
* matches is output to contain the matching features between the two images
* Optionally pass hamming distance and goodness ratio, otherwise flag
* values are used.
**/
void FindMatches(const cv::Mat & img1_descriptor_map,
const cv::Mat & img2_descriptor_map,
std::vector<cv::DMatch> * matches);
void FindMatches(const cv::Mat& img1_descriptor_map, const cv::Mat& img2_descriptor_map,
std::vector<cv::DMatch>* matches, boost::optional<int> hamming_distance = boost::none,
boost::optional<double> goodness_ratio = boost::none);
} // namespace interest_point

#endif // INTEREST_POINT_MATCHING_H_
Loading
Loading