Skip to content

RefineDetectedMarkers fails if cameraMatrix is given as a param #24127

@jlnicks84

Description

@jlnicks84

System Information

OpenCV python version: 4.8.0
Operating System / Platform: Windows 10
Python version: 3.9.16

Detailed description

refineDetectedMarkers method of ArucoDetector fails if optional cameraMatrix param is given.

When running following line,

corners, ids, rejected, _ = aruco_detector.refineDetectedMarkers(
    image=grayscale_image,
    board=charucoboard,
    detectedCorners=aruco_corners,
    detectedIds=aruco_ids,
    rejectedCorners=aruco_rejected,
    cameraMatrix=camera_matrix,
    distCoeffs=dist_coeffs,
)

An assertion error is raised:

    corners, ids, rejected, _ = aruco_detector.refineDetectedMarkers(
cv2.error: OpenCV(4.8.0) D:\bld\libopencv_1690022693676\work\modules\objdetect\src\aruco\aruco_board.cpp:460: error: (-215:Assertion failed) (int)detectedCharucoVecMat[i].total() * detectedCharucoVecMat[i].channels() == 2 in function 'cv::aruco::CharucoBoardImpl::matchImagePoints'

No error is raised if no cameraMatrix is specified.

Steps to reproduce

import imageio.v3 as iio
import numpy as np
import cv2

grayscale_image = iio.imread( r"C:\Users\jnicks\Documents\repositories\camera-characterization\gray_scale_image.png")
camera_matrix = np.array(
    [
        [1.08444638e03, 0.00000000e00, 6.99703945e02],
        [0.00000000e00, 1.08545749e03, 5.24978509e02],
        [0.00000000e00, 0.00000000e00, 1.00000000e00],
    ]
)
dist_coeffs = np.array([0.01183206, 0.01096358, 0.0, 0.0])

charucoboard = cv2.aruco.CharucoBoard(
    (11, 8),
    35,
    26,
    cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50),
)
charucoboard.setLegacyPattern(True)
aruco_detector = cv2.aruco.ArucoDetector(
    dictionary=charucoboard.getDictionary(), detectorParams=cv2.aruco.DetectorParameters()
)
aruco_corners, aruco_ids, aruco_rejected = aruco_detector.detectMarkers(image=grayscale_image)
# following line works
# corners, ids, rejected, _ = aruco_detector.refineDetectedMarkers(
#     image=grayscale_image,
#     board=charucoboard,
#     detectedCorners=aruco_corners,
#     detectedIds=aruco_ids,
#     rejectedCorners=aruco_rejected,
#     distCoeffs=dist_coeffs,
# )
# following line fails
corners, ids, rejected, _ = aruco_detector.refineDetectedMarkers(
    image=grayscale_image,
    board=charucoboard,
    detectedCorners=aruco_corners,
    detectedIds=aruco_ids,
    rejectedCorners=aruco_rejected,
    cameraMatrix=camera_matrix,
    distCoeffs=dist_coeffs,
)

Following image is used as input: gray_scale_image

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions