Skip to content

Conversation

@adrianheron
Copy link
Contributor

@adrianheron adrianheron commented Jan 14, 2018

This pullrequest changes

As described in the documentation https://docs.opencv.org/3.4.0/d5/dae/tutorial_aruco_detection.html the way to manually create custom dictionaries is to edit the bytesList property of the Dictionary object, typically using matrices generated via the Dictionary::getByteListFromBits() function. In the current python bindings bytesList is read-only and Dictionary::getByteListFromBits() is not exported.

This PR makes it possible to manually create custom dictionaries by making bytesList, markerSize, and maxCorrectionBits writable and exporting Dictionary::getByteListFromBits() and Dictionary::getBitsFromByteList().

In python creating a custom dictionary can now be accomplished via this pattern

import numpy as np
from cv2.aruco import custom_dictionary, Dictionary_getByteListFromBits

my_dict = custom_dictionary(2, 3)

bits_H = np.array([[1, 0, 1],
                   [1, 1, 1],
                   [1, 0, 1]],
                  dtype=np.uint8)
bits_I = np.array([[0, 1, 0],
                   [0, 1, 0],
                   [0, 1, 0]],
                  dtype=np.uint8)

my_dict.bytesList = np.array([Dictionary_getByteListFromBits(bits_H)[0],
                              Dictionary_getByteListFromBits(bits_I)[0]])

Tested with Python 2.7, here are the marker images drawn from this custom dictionary:
hi_00 hi_01

@kamrausch
Copy link

I think this will do what I want. My goal is to take a single snapshot with a stereo pair of cameras using several unique boards scattered across the FOV. With this method, I can loop through stationary boards rather than images while moving the cameras on a gimble mount or something similar.

Using this pull request, I can create N custom dictionaries pulling from one common dictionary like 4x4_250 where the beginning of each new custom dictionary starts with the ending of the previous custom dictionary.

It would be convienent to be able to specify the starting marker ID in the board creation but I see that isn’t written that way in the c++ code either.

@kamrausch
Copy link

Thanks for the pointer to the PR btw.

@terfendail
Copy link
Contributor

👍

@alalek alalek merged commit 2d63830 into opencv:master Feb 5, 2018
@adrianheron adrianheron deleted the python_custom_dictionary branch February 12, 2018 19:16
@devernay
Copy link

It would also be great if we could either have ad "id_offset" parameter to CharucoBoard_create to start a given charuco board at some id, or if CharucoBoard.ids could be writable (as with the C++ API). Currently, the only way to may a charuco board starting at - say - id 24 is to create a custom dict containing markers 24 and following from the original dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants