Skip to content

This repository contains a solution for detecting chess pieces in images by utilizing the 'matchTemplate' method.

License

Notifications You must be signed in to change notification settings

arashyeganeh/Chess-Piece-Object-Detection-using-OpenCV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Piece Detection | OpenCV matchTemplate()

python opencv numpy jupyter

This project involves loading multiple images of chess boards and utilizing the matchTemplate method of OpenCV to detect the pieces present on each board. As a result of this process, the output includes a comprehensive list of the detected chess piece names.

Piece Name Short Name Piece Name Short Name
King (White) King (White) K King (black) King (black) k
Queen (white) Queen (White) Q Queen (black) Queen (black) q
Rook (White) Rook (White) R Rook (black) Rook (black) r
Bishop (white) Bishop (White) B Bishop (black) Bishop (black) b
Knight (White) Knight (White) N Knight (black) Knight (black) n
Pawn (White) Pawn (White) P Pawn (black) Pawn (black) p

Requirements

  • Python 3.x
  • OpenCV
  • Numpy

Usage

To get started, first clone the repository and install the necessary dependencies by running the following command:

pip install opencv-python numpy

Next, place the chess board image files in the test/ directory and the chess piece image files in the chess_piece/ directory.

There are two ways to execute the program:

Method 1: Running in Terminal

To run the script in the terminal, use the following command:

python main.py

Method 2: Running in Jupyter Lab

To run the script in Jupyter Lab, open the main.ipynb notebook and execute the code.

Configuration

The following configurations can be adjusted according to the user's preference:

  • SHOW_IMAGE: If set to True, the image with detected pieces will be displayed. Default is True.
  • EXPORT_IMAGE: If set to True, the image with detected pieces will be saved to the dist/ directory. Default is True.
  • chessPieceThreshold: The threshold values for each chess piece can be adjusted according to the image quality. The default values are provided in the script.
  • CHESS_BOARD_OUTPUT_DIR: The directory where the output images will be saved. Default is dist/.

License

This project is licensed under the MIT License.

About

This repository contains a solution for detecting chess pieces in images by utilizing the 'matchTemplate' method.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published