Difference between revisions of "PlayChessWithAWebCam/BoardFinder"
Line 62: | Line 62: | ||
===== Color filtering ===== | ===== Color filtering ===== | ||
Now we can filter the original image with the color ranges found in the mask / histogram steps. | Now we can filter the original image with the color ranges found in the mask / histogram steps. | ||
+ | |||
[[File:image008-colorFiltered-X--7x7.jpg|400px]] | [[File:image008-colorFiltered-X--7x7.jpg|400px]] | ||
[[File:image008-colorFiltered-O--7x7.jpg|400px]] | [[File:image008-colorFiltered-O--7x7.jpg|400px]] |
Revision as of 09:23, 1 December 2019
Source Code
see class BoardFinder in module boardfinder tests are in the test_BoardFinder module
Algorithm
Finding the chessboard
OpenCV has a function findChessboardCorners which is usually used for camera calibration and not really intended for the use case of "real chessboards".
Still it is very helpful and used as a basis for the BoardFinder.
Initializing the BoardFinder
The board finder is initialized with an image. Optionally you can specify the Video instance to be used.
finder = BoardFinder(image,video=video)
finding the chessboard corners
The find method starts the board finding. The Boardfinder will try out different patterns from 7x7 down to 3x3. Since a successfull find is much quicker than an unsuccessful one and since searching a small image is much faster than a big one the width of the searchImages can be specified. The default is 640 pixels. For the 13 tests images the search is even successful when the searchWidth is only 360 pixels. The difference in speed is approximately a factor of 1.5. Searching 13 test images and creating all the debug images takes around 10 seconds.
found=finder.find(limit=1,searchWidth=360)
Examples
Chessboard008 in detail
Polygons
The corners detected can be used to fill the 4 corner polygons. We don't know the colors of the squares yet but we know that a chessboard-pattern was found.
See https://codegolf.stackexchange.com/questions/63772/determine-the-color-of-a-chess-square for some fun code around the issue to determine whether a square is light or dark from its position.
For the time being we guess and might be wrong:
Masking
To find out the colors we mask the detected squares.
Histogram
Now we can create a histogram of the colors found in the two masks
From now on we know which color is white/light and which one is black/dark.
Color filtering
Now we can filter the original image with the color ranges found in the mask / histogram steps.