1

this is the code to generate 4 aruco marker with the given id and save it into the same folder .this is the error when i run the same function for generating multiple aruco marker

import numpy
import cv2
import cv2.aruco as aruco
i=1

def aruco_gen(id_aruco, num_pixels):
  global i

  aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_50)
  print(i)                                                       
  img = aruco.drawMarker(aruco_dict, id_aruco, num_pixels)


  cv2.imshow('frame',img)
  cv2.imwrite('ArUco'+str(id_aruco)+'.jpg',img)
  i=i+1
  cv2.waitKey(0)  
  cv2.destroyAllWindows()


if __name__ == "__main__": 

  aruco_dict={0:[10,400],1:[49,400],2:[74,400],3:[190,400],4:[180,400]}   


  for ar_id,ar_arg in aruco_dict.items():
  id_aruco  =aruco_dict[ar_id][0]
  num_pixels=aruco_dict[ar_id][1]
  aruco_gen(id_aruco,num_pixels)
  print(id_aruco,num_pixels,ar_id)

this is the error i get when i run the program

 1
 10 400 0
 2
 49 400 1
 3

Traceback (most recent call last): File "/home/mighty/Task1.1_test.py", line 98, in aruco_gen(id_aruco,num_pixels) File "/home/mighty/Task1.1_test.py", line 67, in aruco_gen img = aruco.drawMarker(aruco_dict, id_aruco, num_pixels) cv2.error: OpenCV(3.4.2) /io/opencv_contrib/modules/aruco/src/dictionary.cpp:169: error: (-215:Assertion failed) id < bytesList.rows in function 'drawMarker'

[Finished in 1.7s with exit code 1] [shell_cmd: /usr/bin/env python3 /home/mighty/Task1.1_test.py] [dir: /home/mighty/] [path: /home/mighty/bin:/home/mighty/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
mighty
  • 13
  • 6

2 Answers2

0

So, the answer is as follows:
First, I think your definition of dictionary is wrong - try using the following:

aruco_dict = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)

The second thing is that DICT_4X4_50 is limited to id<=50 (not sure if it starts from 0 or 1).

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
0

change

    aruco.DICT_4X4_50  

to

    aruco.DICT_4X4_250

in your case your using 10,49,74,190,180. it crashed when you tried 74.

I didn't test python, but ran into similar problem in c++, and that was the fix.

fatkid
  • 1