Python finchessboardcorners function doesn't work properly on my images

  • Thread starter Thread starter daanvancamp
  • Start date Start date
  • Tags Tags
    pattern recognition
AI Thread Summary
The discussion centers on using OpenCV's findChessboardCorners function in Python to recognize a chessboard pattern. The user reports that the function frequently fails to detect the chessboard, succeeding only about one-sixth of the time. They are utilizing medianBlur to reduce noise but still face issues with detection. The images being processed are JPGs, and the user aims to recognize 196 corners on a 14x14 board, with additional squares present for extrapolation purposes. The presence of colored dots in the images is part of a separate project involving playing gomoku on a physical board. The user seeks advice on improving recognition rates and questions whether the function itself might be problematic.
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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top