opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

Assertion issue on estimatePoseCharucoBoard when charuco board is not fully visible

Open blueshark27 opened this issue 4 years ago • 0 comments

System information (version)
  • OpenCV => master
  • Operating System / Platform => Windows 64 Bit / Python
  • Compiler => Visual Studio
Detailed description

Calling the funcion when the charuco board is not completely detected, raises an assertion.

This is caused by the lines

        int currId = _charucoIds.getMat().at(i);
        CV_Assert(currId >= 0 && currId chessboardCorners.size());

If a charuco point is not detected, its id becomes the value -1.

It can be fixed by removing the entries which contain -1 and its pendants in _charucoCorners.

Steps to reproduce

I attached an image for testing. The charuco board detection was called with the following parameters:

  • charuco_dict: 0
  • charuco_square_lenght: 0.1685
  • charuco_marker_size: 0.11878
  • squaresX: 5
  • squaresY: 7

Since I am working with pyhton, I reimplemented the affected functions in python and there I tested my suggested fix. I tried to stay close to the C++ implementation. You can find the code at the end.

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

partial_charuco

from cv2 import cv2
import numpy as np


def my_estimate_pose_charuco_board(charuco_corners, charuco_ids, board, cameraMatrix, distCoeffs, rvec, tvec, useExtrinsicGuess=False) -> (bool, [], []):
    assert len(charuco_corners) == len(charuco_ids),\
        f"len(charuco_corners): {len(charuco_corners)} - len(_charuco_ids): {len(charuco_ids)}"

    # need, at least, 4 corners
    if len(charuco_ids) = 0 and curr_id  bool:
    assert len(points.shape) == 3
    assert points.shape[1] == 1
    assert points.shape[2] == 3

    if len(points) = 2:
            more_than_2 += 1

    # if we have more than 1 two xvalues with more than 2 points, calibration is ok
    return more_than_2 > 1

blueshark27 avatar Aug 27 '21 15:08 blueshark27