forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(graph_segment, gnss_particle_corrector): make some features s…
…witchable (autowarefoundation#17) * make additional-graph-segment-pickup disablable Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> * enlarge gnss_mahalanobis_distance_threshold in expressway.launch Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp> --------- Signed-off-by: Kento Yabuuchi <kento.yabuuchi.2@tier4.jp>
- Loading branch information
Showing
10 changed files
with
192 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
localization/yabloc/imgproc/graph_segment/include/graph_segment/similar_area_searcher.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 TIER IV, Inc. | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
#include <Eigen/Core> | ||
#include <opencv4/opencv2/core.hpp> | ||
#include <rclcpp/logger.hpp> | ||
|
||
#include <set> | ||
|
||
namespace pcdless::graph_segment | ||
{ | ||
class SimilarAreaSearcher | ||
{ | ||
public: | ||
SimilarAreaSearcher(float similarity_score_threshold) | ||
: similarity_score_threshold_(similarity_score_threshold), | ||
logger_(rclcpp::get_logger("similar_area_searcher")) | ||
{ | ||
} | ||
|
||
std::set<int> search( | ||
const cv::Mat & rgb_image, const cv::Mat & segmented, int best_roadlike_class); | ||
|
||
private: | ||
const float similarity_score_threshold_; | ||
rclcpp::Logger logger_; | ||
}; | ||
} // namespace pcdless::graph_segment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
localization/yabloc/imgproc/graph_segment/src/similar_area_searcher.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2023 TIER IV, Inc. | ||
// | ||
// 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. | ||
|
||
#include "graph_segment/similar_area_searcher.hpp" | ||
|
||
#include "graph_segment/histogram.hpp" | ||
|
||
#include <rclcpp/logging.hpp> | ||
|
||
#include <queue> | ||
|
||
namespace pcdless::graph_segment | ||
{ | ||
struct KeyAndArea | ||
{ | ||
KeyAndArea(int key, int count) : key(key), count(count) {} | ||
int key; | ||
int count; | ||
}; | ||
|
||
std::set<int> SimilarAreaSearcher::search( | ||
const cv::Mat & rgb_image, const cv::Mat & segmented, int best_roadlike_class) | ||
{ | ||
std::unordered_map<int, Histogram> histogram_map; | ||
std::unordered_map<int, int> count_map; | ||
|
||
for (int h = 0; h < rgb_image.rows; h++) { | ||
const int * seg_ptr = segmented.ptr<int>(h); | ||
const cv::Vec3b * rgb_ptr = rgb_image.ptr<cv::Vec3b>(h); | ||
|
||
for (int w = 0; w < rgb_image.cols; w++) { | ||
int key = seg_ptr[w]; | ||
cv::Vec3b rgb = rgb_ptr[w]; | ||
if (count_map.count(key) == 0) { | ||
count_map[key] = 1; | ||
histogram_map[key].add(rgb); | ||
} else { | ||
count_map[key]++; | ||
histogram_map[key].add(rgb); | ||
} | ||
} | ||
} | ||
|
||
auto compare = [](KeyAndArea a, KeyAndArea b) { return a.count < b.count; }; | ||
std::priority_queue<KeyAndArea, std::vector<KeyAndArea>, decltype(compare)> key_queue{compare}; | ||
for (auto [key, count] : count_map) { | ||
key_queue.push({key, count}); | ||
} | ||
|
||
Eigen::MatrixXf ref_histogram = histogram_map.at(best_roadlike_class).eval(); | ||
|
||
std::stringstream debug_ss; | ||
debug_ss << "histogram equality "; | ||
|
||
int index = 0; | ||
std::set<int> acceptable_keys; | ||
while (!key_queue.empty()) { | ||
KeyAndArea key = key_queue.top(); | ||
key_queue.pop(); | ||
|
||
Eigen::MatrixXf query = histogram_map.at(key.key).eval(); | ||
float score = Histogram::eval_histogram_intersection(ref_histogram, query); | ||
debug_ss << " " << score; | ||
|
||
if (score > similarity_score_threshold_) acceptable_keys.insert(key.key); | ||
if (++index > 10) break; | ||
} | ||
RCLCPP_INFO_STREAM(logger_, debug_ss.str()); | ||
|
||
// // DEBUG: Visualilze | ||
// cv::Mat new_segmented = rgb_image.clone(); | ||
// for (int h = 0; h < rgb_image.rows; h++) { | ||
// const int * seg_ptr = segmented.ptr<int>(h); | ||
// cv::Vec3b * rgb_ptr = new_segmented.ptr<cv::Vec3b>(h); | ||
|
||
// for (int w = 0; w < rgb_image.cols; w++) { | ||
// int key = seg_ptr[w]; | ||
// if (acceptable_keys.count(key)) rgb_ptr[w] = cv::Vec3b(0, 0, 255); | ||
// if (key == best_roadlike_class) rgb_ptr[w] = cv::Vec3b(0, 255, 255); | ||
// } | ||
// } | ||
|
||
return acceptable_keys; | ||
} | ||
} // namespace pcdless::graph_segment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.