opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

having a hard time using getBitsFromByteList in Aruco dictionary

Open HagegeR opened this issue 6 years ago • 6 comments

OpenCV => 4.1.0-dev Operating System / Platform => Windows 10 (64 Bit)

Hi,

first of all, thanks for your work!

I'm trying to save and then load a custom dictionary in python (3.6), and I got a problem a the following assertion:

https://github.com/opencv/opencv_contrib/blob/0915b7eaddba3c06d83e201c9a7595e73801f417/modules/aruco/src/dictionary.cpp#L237-L239

I tried to use the predefined dictionary in order to find out if the problem is related to the customized dictionary, but it's not.

a simple test to reproduce my problem is here:

import numpy as np
import cv2
from cv2 import aruco

custom_dictionary = aruco.Dictionary_get(aruco.DICT_4X4_50)
np.save("byteList.npy", custom_dictionary.bytesList)
byteList = np.load("byteList.npy")

dict = aruco.Dictionary_getBitsFromByteList(byteList, 4)

am I doing something wrong? I feel like this part of the code is older and the format of the dictionary changed since.

HagegeR avatar Jul 25 '19 21:07 HagegeR

I think that the assert misses a factor of 4 since it only checks towards the byte size that is needed to recreate the normal rotation, not the other three rotations. A workaround is to pass only the first quarter of the byteList to aruco.Dictionary_getBitsFromByteList().

aolindahl avatar Aug 29 '19 07:08 aolindahl

markerID = 0 # 0~49 for DICT_4X4_50
dict = aruco.Dictionary_getBitsFromByteList(byteList[markerID], 4)

dogod621 avatar Sep 17 '19 07:09 dogod621

Hello, I have the same problem. Any workaround.

bits = aruco.Dictionary_getBitsFromByteList(aruco.Dictionary_get(aruco.DICT_4X4_50).bytesList, 4)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-51-87b5f7e5f917> in <module>
----> 1 bits = aruco.Dictionary_getBitsFromByteList(aruco.Dictionary_get(aruco.DICT_4X4_50).bytesList, 4)

error: OpenCV(4.4.0) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-7r9u7hyj/opencv_contrib/modules/aruco/src/dictionary.cpp:239: error: (-215:Assertion failed) byteList.total() > 0 && byteList.total() >= (unsigned int)markerSize * markerSize / 8 && byteList.total() <= (unsigned int)markerSize * markerSize / 8 + 1 in function 'getBitsFromByteList'

lpierron avatar Dec 11 '20 08:12 lpierron

Its been long since I looked at the code, but if it is the same still try passing only the first quarter och the bytes list.

aolindahl avatar Dec 11 '20 15:12 aolindahl

I found you can have only one marker in the bytesList:

>>> bytes = aruco.Dictionary_get(aruco.DICT_7X7_100).bytesList
>>> bytes.shape
(100, 7, 4)
>>> bits = aruco.Dictionary_getBitsFromByteList(bytes[0:1, :, :], 7)
>>> bits
array([[1, 1, 0, 1, 1, 1, 0],
       [1, 0, 1, 0, 1, 1, 1],
       [0, 0, 0, 1, 1, 0, 1],
       [1, 0, 0, 1, 0, 1, 0],
       [0, 1, 0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 1]], dtype=uint8)
>>> bits = aruco.Dictionary_getBitsFromByteList(bytes[0:2, :, :], 7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.4.0) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-7r9u7hyj/opencv_contrib/modules/aruco/src/dictionary.cpp:239: error: (-215:Assertion failed) byteList.total() > 0 && byteList.total() >= (unsigned int)markerSize * markerSize / 8 && byteList.total() <= (unsigned int)markerSize * markerSize / 8 + 1 in function 'getBitsFromByteList'

But is it possible to have it's own markers, changing some markers in bytesList in Dictionary object ?

lpierron avatar Dec 11 '20 19:12 lpierron

Try bits = aruco.Dictionary_getBitsFromByteList(bytes[1:2, :, :], 7)

iamrobusto avatar Dec 01 '21 06:12 iamrobusto