finchessboardcorners function doesn't work properly on my images

  • Context: Python 
  • Thread starter Thread starter daanvancamp
  • Start date Start date
  • Tags Tags
    pattern recognition
Click For Summary
SUMMARY

The discussion centers on issues with the OpenCV function cv2.findChessboardCorners in Python, specifically its failure to consistently detect chessboard corners in images. The user reports that the function only returns a successful detection approximately one-sixth of the time, despite using median blur to reduce noise. The images used are JPEG format, and the user is attempting to recognize a 14x14 grid of corners, which is part of a larger 15x15 board setup for a gomoku game. Suggestions for improving detection accuracy are sought.

PREREQUISITES
  • Familiarity with OpenCV 4.x and its functions, particularly cv2.findChessboardCorners
  • Understanding of image processing techniques, including median blurring
  • Knowledge of chessboard pattern recognition and corner detection algorithms
  • Basic proficiency in Python programming
NEXT STEPS
  • Research advanced image preprocessing techniques to enhance corner detection accuracy
  • Explore alternative corner detection methods in OpenCV, such as cv2.aruco markers
  • Learn about parameter tuning for cv2.findChessboardCorners to optimize performance
  • Investigate the impact of image resolution and quality on corner detection outcomes
USEFUL FOR

This discussion is beneficial for computer vision developers, robotics engineers, and anyone working on image recognition tasks using OpenCV, particularly those focused on chessboard or grid pattern detection.

daanvancamp
Messages
2
Reaction score
0
Post
I am trying to recognize a chessboardpattern using opencv(cv2) and python.
I use the built-in findchessboardcorners feature which returns nothing if it doesn’t find the hole board.
Right now, I use this code.

Python:
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. The board is only recognized in about a sixth of the cases.

Does anyone know how to improve the recognition? I suppose that I need to reduce noise, but that’s what medianBlur does already. Is it an issue with the function itself?

Here are a few images I used:

1724103369326.png


https://ibb.co/n7vVLtj
https://ibb.co/8cF18c1
https://ibb.co/rpDph1S
https://ibb.co/RQc3jmR
 
Last edited by a moderator:
Technology news on Phys.org
Welcome to PF.

Can you explain what the format of your images is? Why are there so many extra squares (>64)? What do the little colored dots mean? And what is the purpose of the big black finger or foot in the bottom of your image?
 
berkeman said:
Welcome to PF.

Can you explain what the format of your images is? Why are there so many extra squares (>64)? What do the little colored dots mean? And what is the purpose of the big black finger or foot in the bottom of your image?
These are jpg images. I am trying to recognize 196 (14*14) corners, then I use extrapolating to get the remaining corners. (The extrapolating works, so that isn't the problem.) It is about the board, the rest is background that doesn't do anything. The whole experimental code is here if you are interested: the complete experimental code

The little colored dots, where added to test something else. (I am trying to play gomoku against the computer on a physical board.) I use a canvas that contains four boards of 15*15, so 900 squares, but I only use one of them at the moment. I want to recognize the pieces when the findchessboardcorners function works.