finchessboardcorners function doesn't work properly on my images

  • #1
daanvancamp
2
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
  • #2
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?
 
  • #3
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.
 
Back
Top