cv2.findChessboardCorners() running endlessly on certain images

Hi,

First of all thanks for all your contributions to OpenCV.

Problem statement
I’m using OpenCV to find chessboard corners on an image. It can happen that an image is passed into the function that is of bad quality or almost completely black. When this happens, the function just endlessly runs, trying to find the corners.

This feels like a bug to me, given that it completely blocks your application. Is there any way how I can force the function safely to stop for searching after x amount of time?

Reproducing the issue

This issue can easily be reproduced. You can use this image and the following code snippet:

import cv2

test = cv2.imread("/path/to/the/image/27-04-2023_14-13-21_494.png")

found, corners = cv2.findChessboardCorners(image=test,
                                           patternSize=(26, 16),
                                           flags=(cv2.CALIB_CB_FAST_CHECK +
                                                  cv2.CALIB_CB_ADAPTIVE_THRESH +
                                                  cv2.CALIB_CB_NORMALIZE_IMAGE))

print(found)

(note: I had to upload the image to Google Drive as the forum was converting it to .jpeg, which didn’t allow for reproducing the issue.)

You will notice that the function just endlessly keeps running and consuming resources (I’ve let it run for +15 minutes already).

This issue is confirmed both on opencv-python-3.4.18.65 as well as on opencv-python-4.7.0.72

I could not find any other topics or GitHub issues about this topic. If this is confirmed as a bug, I’m happy to create an issue in GitHub.

Thank you in advance!

1 Like

Yes there is a problem.
May be something must be checked in findQuadNeighbors

Thanks for your answer Laurent. I have opened a GitHub issue here.

Until that is fixed, for dark images you could check (for example) their median value and skip the image if that is very low.