-
Notifications
You must be signed in to change notification settings - Fork 0
Thomas refactor #17
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
base: main
Are you sure you want to change the base?
Thomas refactor #17
Conversation
for more information, see https://pre-commit.ci
ci: add ci workflows and config files
otsu filter and refactor
updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.2 → v0.11.4](astral-sh/ruff-pre-commit@v0.9.2...v0.11.4) - [github.com/pre-commit/mirrors-clang-format: v19.1.7 → v20.1.0](pre-commit/mirrors-clang-format@v19.1.7...v20.1.0) - [github.com/codespell-project/codespell: v2.3.0 → v2.4.1](codespell-project/codespell@v2.3.0...v2.4.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
for more information, see https://pre-commit.ci
updates: - [github.com/astral-sh/ruff-pre-commit: v0.11.4 → v0.12.2](astral-sh/ruff-pre-commit@v0.11.4...v0.12.2) - [github.com/pre-commit/mirrors-clang-format: v20.1.0 → v20.1.7](pre-commit/mirrors-clang-format@v20.1.0...v20.1.7)
declare param function
…x-image-filtering into Thomas_refactor
…, blus some finishing tuches in comenting and so on
… story has to go (cant merge to main with it)
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 3 5 +2
Lines 234 464 +230
Branches 18 35 +17
======================================
- Misses 234 464 +230
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
template<typename T>
T declare_and_get(
const std::string& name,
const T& default_value)
{
if (!this->has_parameter(name)) {
this->declare_parameter<T>(name, default_value);
}
return this->get_parameter(name).as<T>();
}Can something like this be used to avoid having to declare all parameters. |
|
Also remove the new filters that are not present on the main branch. This PR should just be a refactor, not add filters |
|
Add namespace vortex::image_filtering to header files |
jorgenfj
left a comment
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.
You should look into splitting up ros and non-ros code in subfolders /lib and /ros and then export /lib as a separate library so that other users can directly import filters into their code. An example of this setup in terms of folder structure and Cmake is here pose_filtering.
Also remove the "Todo" and "examples" from the actual code. It is enough that it is documented in the README how you implement new filters. That should be fine as vortexers have gigachad IQ
| std::cout << "\033[33m No string connected to that filter type: '" << s | ||
| << "'. This might be misspelling or you need to add the filter " | ||
| "type to kFilterMap in image_processing.hpp\033[0m"; |
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.
Consider using spdlog instead. spdlog::warn will return red warning messages.
| static constexpr std::pair<std::string_view, FilterType> kFilterMap[] = { | ||
| {"no_filter", FilterType::NoFilter}, | ||
| {"flip", FilterType::Flip}, | ||
| {"unsharpening", FilterType::Unsharpening}, | ||
| {"erosion", FilterType::Erosion}, | ||
| {"dilation", FilterType::Dilation}, | ||
| {"white_balancing", FilterType::WhiteBalancing}, | ||
| {"ebus", FilterType::Ebus}, | ||
| {"otsu", FilterType::Otsu}, | ||
| {"overlap", FilterType::Overlap}, | ||
| {"median_binary", FilterType::MedianBinary}, | ||
| {"binary", FilterType::Binary}, | ||
|
|
||
| // TODO(Vortex): Also add your filter here | ||
| {"example", FilterType::Example}, | ||
| {"unknown", FilterType::Unknown}}; | ||
|
|
||
| inline std::string to_lower(std::string s) { | ||
| for (char& ch : s) { | ||
| ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch))); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| inline FilterType parse_filter_type(std::string s) { | ||
| s = to_lower(std::move(s)); | ||
|
|
||
| for (auto [name, type] : kFilterMap) { | ||
| if (s == name) | ||
| return type; | ||
| } | ||
| std::cout << "\033[33m No string connected to that filter type: '" << s | ||
| << "'. This might be misspelling or you need to add the filter " | ||
| "type to kFilterMap in image_processing.hpp\033[0m"; | ||
| return FilterType::Unknown; | ||
| } | ||
|
|
||
| inline std::string_view filtertype_to_string(FilterType t) { | ||
| for (auto [name, type] : kFilterMap) { | ||
| if (t == type) | ||
| return name; | ||
| } | ||
| std::cout << "\033[33m No string connected to your filter type. To fix " | ||
| "this add the string and filter type to kFilterMap\033[0m"; | ||
| return "unknown"; |
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.
Can move kFilterMap, to_lower, parse_filter_type, filtertype_to_string be moved to a util header file
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.
maybe to a different header than the one where you keep the image util functions
| inline std::string_view filtertype_to_string(FilterType t) { | ||
| for (auto [name, type] : kFilterMap) { | ||
| if (t == type) | ||
| return name; | ||
| } | ||
| std::cout << "\033[33m No string connected to your filter type. To fix " | ||
| "this add the string and filter type to kFilterMap\033[0m"; | ||
| return "unknown"; | ||
| } |
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.
This should not be needed. For the filtertype setup where this is used, just return early in default case/clause, print the string ros parameter instead of calling this function after the switch case.
| struct FlipParams { | ||
| int flip_code; | ||
| }; |
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.
Can you create an enum class for the different flip codes
| void ImageFilteringNode::set_filter_params() { | ||
| FilterParams params; | ||
| std::string filter = | ||
| std::string filter_type_string = |
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.
Maybe create small helper functions to construct the filter types and place them in a ros utils header file
| void ImageFilteringNode::check_and_subscribe_to_image_topic() { | ||
| std::string image_topic = this->get_parameter("sub_topic").as_string(); |
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.
Can you add a similar function for the publisher
…, and adding somme util files for ros only
Refactoring the structure of the image filtering to give it more functionality trough classes. Updated Readme and comenting