Project dedicated to detect the positions of a chessboard with a mobile phone camera or webcam in real time.
I think, initially, this project could be solved being divided into three main parts or areas, this are grid recognition, pieces recognition and board visualization.
The code of this section can be found at src/grid_recog.ipynb
- Take the image and convert to greyscale.
- Convert the image to canny *1
- Do a hough transform to detect chessboard borders *2
- Delete the lines with less difference within others, for getting only four borders
- Find intersections to get the four corners of the board
- Create a black mask excluiding the quadrangle formed by the corners *3
- Use
cv2.goodFeaturesToTrack()
to recognize all inner corners.
- The canny threshold has to be very precise and setted by the user, I think there's probably a better option for this
- This needs to be done without pieces, before the game starts.
- With this mask you can't move the board during the game
Original image | Canny | Hough lines | Board corners | Try of mask :b |
---|---|---|---|---|
The pieces recognition still not in development, will actualize here when it does. Will be done with machine learning, so probably incluiding scikit-learn
in future.
The code of this section can be found at src/board.py
Creates the visualization with Pygame
library and svg images of pieces. For moving pieces you call on src/main.py
the function board.move(move_notation)
The move_notation
parameter is a string type variable, Eg: "NG1-F3", who abbreviates from "Knight on G1 to F3"
Board positions is defined by a pandas dataframe:
A B C D E F G H
8 r n b q k b n r
7 p p p p p p p p
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
After "pD7-D5" and "NG1-F3":
30/7/23: Created brach "develop" Camera configured
This projet is being developed with a git Flow structure, for clean and organizated flow of work.
You're invited to colaborate forking this repo and creating a pull request. Always with a detailed dsecription and clean code.
You can contact me at: [email protected]