Code Monkey home page Code Monkey logo

chess-ai's Introduction

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]

chess-ai's People

Contributors

jomarkow avatar

Stargazers

lautaro lammers avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.