I am working with OpenCV ArUco in Python. I am trying to generate multiple codes of different directories. To generate it in a single time I am using this function in a loop. For example list1 =[1,2,3,4],comb = [50,100,250,1000],ids = [1,22,3,45]
def generator(bsize,comb,ids):
bitsize = [bsize]+['X']+[bsize]
bitz = ''.join(bitsize)
dicts = ['DICT']+[bitz]+[comb]
dictionary = '_'.join(dicts)
print(dictionary)
path = ['aruco']+[dictionary]
print(path)
path = '.'.join(path)
print(path)
aruco_dict = aruco.Dictionary_get(path)
img = aruco.drawMarker(aruco_dict, ids, bsize)
cv2.imshow('frame',img)
for i in range(0,7):
generator(list1[i],list2[i],list3[i])
the output of 'path' is:
aruco.DICT_4X4_1000
after that I am getting error:
line 35, in generator
aruco_dict = aruco.Dictionary_get(path)
TypeError: an integer is required (got type str)
How do I resolve this error. Please help
"aruco.DICT_4X4_1000"
, a string, is different from aruco.DICT_4X4_1000
, an attribute in aruco
.
If you want to programmatically access aruco
's value for the attribute DICT_4X4_1000
, you can use:
getattr(aruco, "DICT_4X4_1000")
So your code for getting path
should be:
...
path = getattr(aruco, dictionary)
...