My approach for the problem is to perform color-segmentation to get a binary mask. Next, using binary mask to remove the background to make the board visible, removed from artifacts. Finally output the chess border features in an accurate way.

    1. Performing color-segmentation: We convert the loaded image to the HSV format define lower/upper ranges and perform color segmentation using cv2.inRange to obtain a binary mask.
    1. Extracting chess-board: After obtaining binary mask we will use it to remove the background and separate chess part from the rest of the image using cv2.bitwise_and. Arithmetic operation and is highly useful for defining roi in hsv colored images.
    1. Displaying chess-board features. After extracting the chessboard from the image, we will set the patternSizeto (7, 7) and flags to adaptive_thresh + fast_check + normalize image inspired from the source.

Steps:

  • Color-segmentation to get the binary mask.

    • lwr = np.array([0, 0, 143])
      upr = np.array([179, 61, 252])
      hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
      msk = cv2.inRange(hsv, lwr, upr)
      
  • Removing background using mask

    • krn = cv2.getStructuringElement(cv2.MORPH_RECT, (50, 30))
      dlt = cv2.dilate(msk, krn, iterations=5)
      res = 255 - cv2.bitwise_and(dlt, msk)
      
  • Displaying Chess-board features

    • res = np.uint8(res)
      ret, corners = cv2.findChessboardCorners(res, (7, 7),
                                               flags=cv2.CALIB_CB_ADAPTIVE_THRESH +
                                                     cv2.CALIB_CB_FAST_CHECK +
                                                     cv2.CALIB_CB_NORMALIZE_IMAGE)
      if ret:
          print(corners)
          fnl = cv2.drawChessboardCorners(img, (7, 7), corners, ret)
          cv2.imshow("fnl", fnl)
          cv2.waitKey(0)
      else:
          print("No Checkerboard Found")
      

Code:


import cv2
import numpy as np

# Load the image
img = cv2.imread("kFM1C.jpg")

# Color-segmentation to get binary mask
lwr = np.array([0, 0, 143])
upr = np.array([179, 61, 252])
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
msk = cv2.inRange(hsv, lwr, upr)

# Extract chess-board
krn = cv2.getStructuringElement(cv2.MORPH_RECT, (50, 30))
dlt = cv2.dilate(msk, krn, iterations=5)
res = 255 - cv2.bitwise_and(dlt, msk)

# Displaying chess-board features
res = np.uint8(res)
ret, corners = cv2.findChessboardCorners(res, (7, 7),
                                         flags=cv2.CALIB_CB_ADAPTIVE_THRESH +
                                               cv2.CALIB_CB_FAST_CHECK +
                                               cv2.CALIB_CB_NORMALIZE_IMAGE)
if ret:
    print(corners)
    fnl = cv2.drawChessboardCorners(img, (7, 7), corners, ret)
    cv2.imshow("fnl", fnl)
    cv2.waitKey(0)
else:
    print("No Checkerboard Found")

To find lower and upper boundaries of the mask, you may find useful: HSV-Threshold-script

Answer from Ahmet on Stack Overflow
Top answer
1 of 2
9

My approach for the problem is to perform color-segmentation to get a binary mask. Next, using binary mask to remove the background to make the board visible, removed from artifacts. Finally output the chess border features in an accurate way.

    1. Performing color-segmentation: We convert the loaded image to the HSV format define lower/upper ranges and perform color segmentation using cv2.inRange to obtain a binary mask.
    1. Extracting chess-board: After obtaining binary mask we will use it to remove the background and separate chess part from the rest of the image using cv2.bitwise_and. Arithmetic operation and is highly useful for defining roi in hsv colored images.
    1. Displaying chess-board features. After extracting the chessboard from the image, we will set the patternSizeto (7, 7) and flags to adaptive_thresh + fast_check + normalize image inspired from the source.

Steps:

  • Color-segmentation to get the binary mask.

    • lwr = np.array([0, 0, 143])
      upr = np.array([179, 61, 252])
      hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
      msk = cv2.inRange(hsv, lwr, upr)
      
  • Removing background using mask

    • krn = cv2.getStructuringElement(cv2.MORPH_RECT, (50, 30))
      dlt = cv2.dilate(msk, krn, iterations=5)
      res = 255 - cv2.bitwise_and(dlt, msk)
      
  • Displaying Chess-board features

    • res = np.uint8(res)
      ret, corners = cv2.findChessboardCorners(res, (7, 7),
                                               flags=cv2.CALIB_CB_ADAPTIVE_THRESH +
                                                     cv2.CALIB_CB_FAST_CHECK +
                                                     cv2.CALIB_CB_NORMALIZE_IMAGE)
      if ret:
          print(corners)
          fnl = cv2.drawChessboardCorners(img, (7, 7), corners, ret)
          cv2.imshow("fnl", fnl)
          cv2.waitKey(0)
      else:
          print("No Checkerboard Found")
      

Code:


import cv2
import numpy as np

# Load the image
img = cv2.imread("kFM1C.jpg")

# Color-segmentation to get binary mask
lwr = np.array([0, 0, 143])
upr = np.array([179, 61, 252])
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
msk = cv2.inRange(hsv, lwr, upr)

# Extract chess-board
krn = cv2.getStructuringElement(cv2.MORPH_RECT, (50, 30))
dlt = cv2.dilate(msk, krn, iterations=5)
res = 255 - cv2.bitwise_and(dlt, msk)

# Displaying chess-board features
res = np.uint8(res)
ret, corners = cv2.findChessboardCorners(res, (7, 7),
                                         flags=cv2.CALIB_CB_ADAPTIVE_THRESH +
                                               cv2.CALIB_CB_FAST_CHECK +
                                               cv2.CALIB_CB_NORMALIZE_IMAGE)
if ret:
    print(corners)
    fnl = cv2.drawChessboardCorners(img, (7, 7), corners, ret)
    cv2.imshow("fnl", fnl)
    cv2.waitKey(0)
else:
    print("No Checkerboard Found")

To find lower and upper boundaries of the mask, you may find useful: HSV-Threshold-script

2 of 2
3

In my environment (opencv-python 4.7.0.68, opencv 4.5.4), just converting it to grey scale can make it work without additional adjustment (at least detected all but the lower left corners). After downsample by resize(), all corners are detected.

img_captured = cv2.imread('example.jpg', cv2.IMREAD_GRAYSCALE)
# img_captured = cv2.resize(img_captured, (350, 350))

GRID = (7, 7)

found, corners = cv2.findChessboardCorners(
    img_captured, GRID, cv2.CALIB_CB_ADAPTIVE_THRESH)

cv2.drawChessboardCorners(img_captured_corners, GRID, corners, found)
cv2.imshow('img_captured_corners', img_captured_corners)

findChessboardCorners no resize

There is also findChessboardCornersSB. From my experience, it works generally better than the plain version. However, I don't know benchmark difference between the two methods.

findChessboardCornersSB

🌐
LearnOpenCV
learnopencv.com › home › camera calibration › camera calibration using opencv
Camera Calibration using OpenCV | LearnOpenCV
July 31, 2026 - OpenCV provides a builtin function called findChessboardCorners that looks for a checkerboard and returns the coordinates of the corners. Let’ see the usage in the code block below.
Discussions

cv2.findChessboardCorners() running endlessly on certain images
I initially opened a topic on the OpenCV forum, but there it was confirmed that it's a bug, hence why I'm also opening a bug report here. This issue is a problem to me because it completely blocks my application when this happens. This issue can easily be reproduced. ... import cv2 test = cv2.imread("/path/to/the/image/27-04-2023_14-13-21_494.png") found, corners = cv2.findChessboardCorners... More on github.com
🌐 github.com
8
April 28, 2023
image processing - How does OpenCV find chessboard corners? - Signal Processing Stack Exchange
What are the internal workings of the OpenCV function findChessboardCorners? More on dsp.stackexchange.com
🌐 dsp.stackexchange.com
July 5, 2012
OpenCV (cv2) Python findChessboardCorners failing on seemingly simple chessboard - Stack Overflow
I have the following images of a chessboard taken from a camera: Here is my minimal working example code: import cv2 print(cv2.__version__) left_gray = cv2.imread('left_raw.jpg', cv2. More on stackoverflow.com
🌐 stackoverflow.com
[Question] What is being returned by findChessboardCorners
Which programming language are you using? More on reddit.com
🌐 r/opencv
8
2
April 21, 2021
🌐
Shimat
shimat.github.io › opencvsharp_docs › html › 797e394c-325b-405d-7423-c800130de3bc.htm
Cv2.FindChessboardCorners Method (InputArray, Size, Point2f[], ChessboardFlags)
Namespace: OpenCvSharp Assembly: OpenCvSharp (in OpenCvSharp.dll) Version: 1.0.0 ... public static bool FindChessboardCorners( InputArray image, Size patternSize, out Point2f[] corners, ChessboardFlags flags = ChessboardFlags.AdaptiveThresh|ChessboardFlags.NormalizeImage )
🌐
Uoit
csundergrad.science.uoit.ca › courses › cv-notes › notebooks › 02-camera-calibration.html
Camera Calibration in OpenCV - Notebook
Use the findChessboardCorners function built-in to OpenCV to extract the corners from the image gray.
🌐
Amroamroamro
amroamroamro.github.io › mexopencv › matlab › cv.findChessboardCorners.html
cv.findChessboardCorners - mexopencv
[corners,ok] = cv.findChessboardCorners(im, patternSize) [...] = cv.findChessboardCorners(..., 'OptionName', optionValue, ...)
🌐
OpenCV
docs.opencv.org › 4.13.0 › dc › dbb › tutorial_py_calibration.html
OpenCV: Camera Calibration
bool findChessboardCorners(InputArray image, Size patternSize, OutputArray corners, int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE)
🌐
The Neural Base
theneuralbase.com › home › opencv › intermediate course › cv2.findchessboardcorners()
cv2.findChessboardCorners() | Opencv Intermediate Course | The Neural Base
VERSION cv2.findChessboardCorners() behavior is stable in opencv-python 4.x. Ensure you're using 4.5.0+ for best performance; earlier 4.x versions had slower detection.
Find elsewhere
🌐
LearnOpenCV
learnopencv.com › home › findchessboardcorners
findChessboardCorners | LearnOpenCV
FREE OpenCV Crash Course · Getting Started Guides · Installation Packages · C++ And Python Examples · Newsletter Insights · We hate SPAM and promise to keep your email address safe. Subscribe To Receive · FREE OpenCV Crash Course · Getting Started Guides ·
🌐
GitHub
github.com › opencv › opencv › issues › 23558
cv2.findChessboardCorners() running endlessly on certain images · Issue #23558 · opencv/opencv
April 28, 2023 - I initially opened a topic on the OpenCV forum, but there it was confirmed that it's a bug, hence why I'm also opening a bug report here. This issue is a problem to me because it completely blocks my application when this happens. This issue can easily be reproduced. ... 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)
Author: opencv
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-find-patterns-in-a-chessboard-using-opencv-python
How to find patterns in a chessboard using OpenCV Python?
March 26, 2026 - Finding chessboard patterns is essential for camera calibration and computer vision applications. OpenCV provides two key functions: cv2.findChessboardCorners() to detect corner points and cv2.drawChessboardCorners() to visualize the detected ...
🌐
Medium
medium.com › analytics-vidhya › camera-calibration-with-opencv-f324679c6eb7
Camera Calibration with OpenCV. How to perform camera calibration and… | by Teja Kummarikuntla | Analytics Vidhya | Medium
March 11, 2026 - Open CV helps to automatically detect the corners and draw on it by findChessboardCorners() and drawChessboardCorners() Applying both functions to a sample image, results: ... import numpy as np import cv2 import matplotlib.pyplot as plt import ...
🌐
Shimat
shimat.github.io › opencvsharp_docs › html › 1bb9a01e-776b-75e5-8451-53c9392f6970.htm
Cv2.FindChessboardCorners Method
OpenCvSharp · Cv2 Class · Cv2 Methods · FindChessboardCorners Method · FindChessboardCorners Method (InputArray, Size, OutputArray, ChessboardFlags) FindChessboardCorners Method (InputArray, Size, Point2f[], ChessboardFlags) Overload List · Top · See Also ·
🌐
Reddit
reddit.com › r/opencv › [question] what is being returned by findchessboardcorners
r/opencv on Reddit: [Question] What is being returned by findChessboardCorners
April 21, 2021 -

Hi,

So I’m using opencv and need to find the coordinates of the corners on a chessboard. My current approach is to take the return value of findChessboardCorners, then do math to determine the outer coordinates, then draw circles at each point.

I know there is drawChessboardCorners, but for this project I can’t quite use that. So when I went to draw the circles at the coordinates, I realized that the coordinates returned are not integers. So what exactly are they? I had been assuming they were the coordinates of the corners. I went through documentation and searched around for a while but can’t seem to find anything.

Any help is appreciated, thank you.

🌐
Reddit
reddit.com › r/opencv › [question] find chessboard corners function help
r/opencv on Reddit: [Question] Find Chessboard Corners Function Help
June 24, 2025 -

Hello guys, I am trying to create a calibration script for a project I am in. Here is the general idea, I will have a reference image with the camera in the correct location. I will find the chessboard corners and save it in a text file. Then, when I calibrate the camera, I will take another image (Ill call it test image) and will get the chessboard corners and save that in a text file. I already have a script that reads in the text file corners and will create a homography matrix and perspective warp the test image to essentially look like the reference image.

I have been struggling to consistently get the chessboard corners function to actually find the corners. I do have some fundamental issues to overcome:

  • There are 4 smaller chessboards in the corner, that all always fixed there.

  • Lighting is not constant.

After cutting the image into quadrants for each chessboard, I have been doing is a mix of image processing techniques. CLAHE, blurring, adaptive filtering for lighting, sobel masks for edge detection as well as some the techniques from this form:

https://stackoverflow.com/questions/66225558/cv2-findchessboardcorners-fails-to-find-corners

I tried different chessboard sizes from 9x6 to 4x3. What are your guys approaches for this matter, so I can get a consistent chessboard corner detection script.

I can only post one image since I am a new user but here is the pipeline of all the image processing techniques. You can see the chessboard rather clearly but the actual function cannot for whatever reason.

diagnostic_pipeline_dot_img_test21920×1280 163 KB

I am writing this debug code in Python but the actual script will run on my Raspberry Pi with C++.

🌐
OpenCV-Python Tutorials
opencv24-python-tutorials.readthedocs.io › en › latest › py_tutorials › py_calib3d › py_calibration › py_calibration.html
Camera Calibration — OpenCV-Python Tutorials beta documentation
So to find pattern in chess board, we use the function, cv2.findChessboardCorners(). We also need to pass what kind of pattern we are looking, like 8x8 grid, 5x5 grid etc. In this example, we use 7x6 grid. (Normally a chess board has 8x8 squares and 7x7 internal corners).
🌐
Physics Forums
physicsforums.com › more sciences and computing › ai and computer science
finchessboardcorners function doesn't work properly on my images • Physics Forums
August 19, 2024 - img=cv2.imread(path_board) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.medianBlur(gray, 5) ret, corners = cv2.findChessboardCorners(gray, number_of_corners, flags=cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK + cv2.CALIB_CB_NORMALIZE_IMAGE + cv2.CALIB_CB_EXHAUSTIVE) if ret == True: print("Chessboard detected") img_with_corners = cv2.drawChessboardCorners(img_with_corners, (BOARD_SIZE + 1,BOARD_SIZE + 1), all_corners.reshape(-1, 1, 2), ret) else: print("No chessboard detected") Most of the time, the function only sets the value of ret to False, which means that it didn’t find anything.
🌐
OpenCV
forum.opencv.org › python
cv2.findChessboardCorners() running endlessly on certain images - Python - OpenCV
April 27, 2023 - 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.