Skip to content

Chess camera AI Project, dedicated to detect the positions of a chessboard with a mobile phone camera or webcam in real time.

Notifications You must be signed in to change notification settings

jomarkow/Chess-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess camera AI

Project dedicated to detect the positions of a chessboard with a mobile phone camera or webcam in real time.

Maintained

Made with:

Python Jupyter OpenCV NumPy

Development detailed

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.

Grid recognition:

The code of this section can be found at src/grid_recog.ipynb

  1. Take the image and convert to greyscale.
  2. Convert the image to canny *1
  3. Do a hough transform to detect chessboard borders *2
  4. Delete the lines with less difference within others, for getting only four borders
  5. Find intersections to get the four corners of the board
  6. Create a black mask excluiding the quadrangle formed by the corners *3
  7. Use cv2.goodFeaturesToTrack() to recognize all inner corners.

Grid recognition Issues:

  1. The canny threshold has to be very precise and setted by the user, I think there's probably a better option for this
  2. This needs to be done without pieces, before the game starts.
  3. With this mask you can't move the board during the game

Images:

Original image Canny Hough lines Board corners Try of mask :b
b46f5b3c-ae09-49bd-936f-49f04a0f9758.jpg image.png image.png image.png image.png

Pieces recognition:

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.

Board visualization:

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":

image.png

30/7/23: Created brach "develop" Camera configured

Workflow and Colaborate

This projet is being developed with a git Flow structure, for clean and organizated flow of work. gitflow-1.png

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]

About

Chess camera AI Project, dedicated to detect the positions of a chessboard with a mobile phone camera or webcam in real time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages