Search code examples
pythonopencvcomputer-visionaruco

Error using board_create for aruco markers due to objPoints type


I want to be able to detect aruco markers on a 3D object and I'm therefore trying to create my own custom aruco board in OpenCV, with the locations of the markers.

I have produced a snippet of the code, to reproduce the error.

# Load the ArUco dictionary
arucoDict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
arucoParams = cv2.aruco.DetectorParameters_create() 

#Create new custom aruco board
board_corners = [np.array([[0.007,0.096,0.0],[0.099,0.096,0.0],[0.099,0.005,0.0],[0.007,0.005,0.0]],dtype=np.float32),
np.array([[0.0,0.099,0.006],[0.0,0.005,0.006],[0.0,0.005,0.096],[0.0,0.099,0.096]],dtype=np.float32),
np.array([[0.007,0.0,0.006],[0.099,0.0,0.006],[0.099,0.0,0.097],[0.007,0.0,0.097]],dtype=np.float32),
np.array([[0.007,0.096,0.103],[0.007,0.005,0.103],[0.099,0.005,0.103],[0.099,0.096,0.103]],dtype=np.float32)]

#Id's for aruco marker on board
board_ids = np.array([[0],[1],[2],[3]], dtype=np.int32)

#Creating board
board = cv2.aruco.Board_create(board_corners,arucoDict, board_ids )

which produce the following error

cv2.error: /build/opencv-L2vuMj/opencv-3.2.0+dfsg/contrib/modules/aruco/src/aruco.cpp:1281: error: (-215) objPoints.type() == CV_32FC3 in function create

From what I understand the error happens when the datatype is not in float32, as the function requires. But I already changed the datatype to np.float32 and I'm not sure why I still get the error.

Hope someone knows what I have missed.


Solution

  • I managed to solve the problem myself. The problem was I was running a too old version of OpenCV. The version needs to be 3.4.x or above since it was a bug that got fixed in 3.4.