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

Fix compatibility with OpenCV 4.7.0 #589

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project are documented in this file.

### Fix
- Return an invalid `PolyDriverDescriptor` if `description` is not found in `constructMultipleAnalogSensorsRemapper()` (https://github.com/ami-iit/bipedal-locomotion-framework/pull/569)
- Fix compatibility with OpenCV 4.7.0 (https://github.com/ami-iit/bipedal-locomotion-framework/pull/589)

## [0.11.1] - 2022-12-19
### Fix
Expand Down
12 changes: 12 additions & 0 deletions src/Perception/src/ArucoDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class ArucoDetector::Impl
/**
* Utility map for choosing Aruco marker dictionary depending on user parameter
*/
// TODO(traversaro): when we drop support for OpenCV < 4.7.0, we can cleanup this part
// we can also check if there are other dictionary that should be added here
#if (CV_VERSION_MAJOR >= 5) || (CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 7)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, there are certainly other dictionaries to be added here. I remember experiencing this issue earlier and purposefully leaving out some dictionaries from the lookup.

Apriltags are not added here. https://docs.opencv.org/3.4/dc/df7/dictionary_8hpp.html

#define PREDEFINED_DICTIONARY_NAME PredefinedDictionaryType
#endif
std::unordered_map<std::string, cv::aruco::PREDEFINED_DICTIONARY_NAME>
availableDict{{"4X4_50", cv::aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_50},
{"4X4_100", cv::aruco::PREDEFINED_DICTIONARY_NAME::DICT_4X4_100},
Expand Down Expand Up @@ -115,7 +120,14 @@ bool ArucoDetector::initialize(std::weak_ptr<const IParametersHandler> handler)
return false;
}

// In OpenCV 4.7.0 getPredefinedDictionary started returning a cv::aruco::Dictionary
// instead of a cv::Ptr<cv::aruco::Dictionary>
#if (CV_VERSION_MAJOR >= 5) || (CV_VERSION_MAJOR == 4 && CV_VERSION_MINOR >= 7)
m_pimpl->dictionary = cv::makePtr<cv::aruco::Dictionary>();
*(m_pimpl->dictionary) = cv::aruco::getPredefinedDictionary(m_pimpl->availableDict.at(dictName));
#else
m_pimpl->dictionary = cv::aruco::getPredefinedDictionary(m_pimpl->availableDict.at(dictName));
#endif

if (!handle->getParameter("marker_length", m_pimpl->markerLength))
{
Expand Down