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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top