diff --git a/modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp b/modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp index 2770a23e36..e944c09a54 100644 --- a/modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp +++ b/modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp @@ -373,11 +373,65 @@ public: CV_WRAP void detectMarkersMultiDict(InputArray image, OutputArrayOfArrays corners, OutputArray ids, OutputArrayOfArrays rejectedImgPoints = noArray(), OutputArray dictIndices = noArray()) const; + /** @brief Returns a specific dictionary from the set of dictionaries used for marker detection. + * + * @param index Index of the dictionary to retrieve. Default is 0, returning the first dictionary if multiple are set. + * + * Returns the dictionary at the specified index from the internal collection of dictionaries used by the ArucoDetector. + * If only one dictionary is set, or if the index is 0, this method will return that dictionary. + * If multiple dictionaries are in use (e.g., for dictionary cascade), this allows access to each dictionary individually. + * @note If the index is out of bounds, the function throws an error. + */ CV_WRAP const Dictionary& getDictionary(int index = 0) const; + + /** @brief Sets a specific dictionary in the list of dictionaries used for marker detection, replacing the dictionary at the given index. + * + * @param dictionary The dictionary to set at the specified index. + * @param index Index of the dictionary to set. Default is 0, replacing the first dictionary if multiple are set. + * + * Sets the dictionary at the specified index within the internal collection of dictionaries used by the ArucoDetector. + * If implementing a dictionary cascade or similar, this method allows for replacing specific dictionaries within the collection. + * @note If the index is out of bounds, the method is going to throw an error. + */ CV_WRAP void setDictionary(const Dictionary& dictionary, int index = 0); + + /** @brief Returns all dictionaries currently used for marker detection as a vector. + * + * @return A constant reference to a std::vector containing all dictionaries used by the ArucoDetector. + * + * Provides access to the entire set of Dictionary objects currently configured within the ArucoDetector. + * This is useful for inspecting the dictionaries being used, iterating through them, or determining the number of dictionaries in use. + */ CV_WRAP const std::vector& getDictionaries() const; + + /** @brief Sets the entire collection of dictionaries to be used for marker detection, replacing any existing dictionaries. + * + * @param dictionaries A std::vector containing the new set of dictionaries to be used. + * + * Configures the ArucoDetector to use the provided vector of Dictionary objects for marker detection. + * This method replaces any dictionaries that were previously set. + * @note Setting an empty vector of dictionaries will throw an error. + */ CV_WRAP void setDictionaries(const std::vector& dictionaries); + + /** @brief Adds a new dictionary to the collection of dictionaries used for marker detection. + * + * @param dictionary The dictionary to add to the collection. + * + * Appends the provided Dictionary object to the internal collection of dictionaries used by the ArucoDetector. + * This method is useful when you want to extend the set of dictionaries already in use without replacing them entirely. + */ CV_WRAP void addDictionary(const Dictionary& dictionary); + + /** @brief Removes a dictionary from the collection of dictionaries at the specified index. + * + * @param index Index of the dictionary to remove from the collection. + * + * Removes the Dictionary object at the specified index from the internal collection of dictionaries. + * After removing a dictionary, the indices of subsequent dictionaries in the collection will be shifted. + * @note If the index is out of bounds, the function will throw. It will also not allow removing the last + * dictionary of the internal collection. + */ CV_WRAP void removeDictionary(int index); CV_WRAP const DetectorParameters& getDetectorParameters() const; diff --git a/modules/objdetect/src/aruco/aruco_detector.cpp b/modules/objdetect/src/aruco/aruco_detector.cpp index 62f34e486b..3fabaf94c7 100644 --- a/modules/objdetect/src/aruco/aruco_detector.cpp +++ b/modules/objdetect/src/aruco/aruco_detector.cpp @@ -648,7 +648,7 @@ enum class DictionaryMode { struct ArucoDetector::ArucoDetectorImpl { /// dictionaries indicates the types of markers that will be searched - std::vector dictionaries; + vector dictionaries; /// marker detection parameters, check DetectorParameters docs to see available settings DetectorParameters detectorParams; @@ -657,7 +657,7 @@ struct ArucoDetector::ArucoDetectorImpl { RefineParameters refineParams; ArucoDetectorImpl() {} - ArucoDetectorImpl(const std::vector&_dictionaries, const DetectorParameters &_detectorParams, + ArucoDetectorImpl(const vector&_dictionaries, const DetectorParameters &_detectorParams, const RefineParameters& _refineParams): dictionaries(_dictionaries), detectorParams(_detectorParams), refineParams(_refineParams) { CV_Assert(!dictionaries.empty()); @@ -838,7 +838,7 @@ struct ArucoDetector::ArucoDetectorImpl { // Clean up rejectedImgPoints by comparing to itself and all candidates const float epsilon = 0.000001f; - auto compareCandidates = [epsilon](std::vector a, std::vector b) { + auto compareCandidates = [epsilon](vector a, vector b) { for (int i = 0; i < 4; i++) { if (std::abs(a[i].x - b[i].x) > epsilon || std::abs(a[i].y - b[i].y) > epsilon) { return false; @@ -1113,7 +1113,7 @@ ArucoDetector::ArucoDetector(const Dictionary &_dictionary, arucoDetectorImpl = makePtr(vector{_dictionary}, _detectorParams, _refineParams); } -ArucoDetector::ArucoDetector(const std::vector &_dictionaries, +ArucoDetector::ArucoDetector(const vector &_dictionaries, const DetectorParameters &_detectorParams, const RefineParameters& _refineParams) { arucoDetectorImpl = makePtr(_dictionaries, _detectorParams, _refineParams); @@ -1454,6 +1454,7 @@ const vector& ArucoDetector::getDictionaries() const { } void ArucoDetector::setDictionaries(const vector& dictionaries) { + CV_Assert(!dictionaries.empty()); arucoDetectorImpl->dictionaries = dictionaries; }