1

I am trying to reverse engineer an aruco board from detecting it in an image.

I made a snippet to reproduce the same problem when creating the GridBoard and then trying to use create_Board on the detected corners and ids on the created image.

# Settings for the marker
max_amount_of_markers_w = 10
max_amount_of_markers_h = 6
ar = aruco.DICT_6X6_1000
aruco_dict = aruco.Dictionary_get(ar)

# creat an aruco Board
grid_board = cv2.aruco.GridBoard_create(max_amount_of_markers_w,
                                        max_amount_of_markers_h,
                                        0.05,
                                        0.01,
                                        aruco_dict)

# convert to image
img = grid_board.draw((1920,180))

# detected corners and ids
corners,ids,rejected = aruco.detectMarkers(img,
                                           aruco_dict)

# convert to X,Y,Z
new_corners = np.zeros(shape=(len(corners),4,3))
for cnt,corner in enumerate(corners):
    new_corners[cnt,:,:-1] = corner

# try to create a board via Board_create
aruco.Board_create(new_corners,aruco_dict,ids)

The error comes from the last line, the error is the following:

error: OpenCV(4.1.1) C:\projects\opencv-python\opencv_contrib\modules\aruco\src\aruco.cpp:1458: error: (-215:Assertion failed) objPoints.type() == CV_32FC3 || objPoints.type() == CV_32FC1 in function 'cv::aruco::Board::create'

This means that it needs something with 3 channels (for x,y and z) which is given as the numpy array.

Kev1n91
  • 3,553
  • 8
  • 46
  • 96

1 Answers1

4

A bit late but I just came across the same problem, so I'll answer for posterity.

The error is not linked to the number of channels that is correct, but linked to the datatype of new_corners, here new_corners.dtype == np.float64. But OpenCV asks for a 32-bit float, as your error shows with CV_32F. A simple cast of new_corners fixes the issue. Your last line becomes :

aruco.Board_create(new_corners.astype(np.float32),aruco_dict,ids)

Jux
  • 49
  • 5