简体   繁体   English

由于 objPoints 的类型不正确,将 board_create 用于 aruco 标记会导致错误

[英]Using board_create for aruco markers leads to error due to objPoints not in the correct type

I am trying to reverse engineer an aruco board from detecting it in an image.我正在尝试通过在图像中检测到它来对 aruco 板进行逆向工程。

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.在创建 GridBoard 然后尝试在创建的图像上检测到的角和 id 上使用 create_Board 时,我制作了一个片段来重现相同的问题。

# 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 ||错误:OpenCV(4.1.1) C:\\projects\\opencv-python\\opencv_contrib\\modules\\aruco\\src\\aruco.cpp:1458: 错误: (-215:Assertion failed) objPoints.type() == CV_32FC3 || objPoints.type() == CV_32FC1 in function 'cv::aruco::Board::create' objPoints.type() == CV_32FC1 在函数 '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.这意味着它需要具有 3 个通道(用于 x、y 和 z)的东西,这些通道作为 numpy 数组给出。

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 .错误与正确的通道数new_corners ,而是与new_corners的数据类型new_corners ,这里是new_corners.dtype == np.float64 But OpenCV asks for a 32-bit float, as your error shows with CV_32F .但是 OpenCV 要求一个 32 位浮点数,因为您的错误显示为CV_32F A simple cast of new_corners fixes the issue.一个简单的new_corners解决了这个问题。 Your last line becomes :你的最后一行变成:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM