All Projects → Vatsalparsaniya → Realtime-OpenCV-Chess

Vatsalparsaniya / Realtime-OpenCV-Chess

Licence: other
♔ Chess-playing with Open-CV [Human vs AI (Stockfish engine)]

Programming Languages

C++
36643 projects - #6 most used programming language
python
139335 projects - #7 most used programming language
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to Realtime-OpenCV-Chess

stockfish-chess-web-gui
Responsive chess web GUI to play against the Stockfish 10 chess engine. Multiple web GUI implementations have also been included.
Stars: ✭ 21 (+16.67%)
Mutual labels:  chess-engine, chess, stockfish-engine
Bit-Genie
UCI chess engine in C++
Stars: ✭ 19 (+5.56%)
Mutual labels:  chess-engine, chess
renpy-chess
A chess GUI built with Ren'Py, python-chess, and Stockfish. Version 2.0 of https://github.com/RuolinZheng08/renpy-chess-engine
Stars: ✭ 36 (+100%)
Mutual labels:  chess-engine, chess
Zerofish
An implementation of the AlphaZero algorithm for chess
Stars: ✭ 34 (+88.89%)
Mutual labels:  chess-engine, chess
liground
A free, open-source and modern Chess Variant Analysis GUI for the 21st century
Stars: ✭ 41 (+127.78%)
Mutual labels:  chess-engine, chess
bot-o-tron
Try out lichess' bot interface
Stars: ✭ 36 (+100%)
Mutual labels:  chess-engine, chess
Sunfish
Sunfish: a Python Chess Engine in 111 lines of code
Stars: ✭ 2,254 (+12422.22%)
Mutual labels:  chess-engine, chess
Walleye
A chess engine written from scratch in Rust ♞
Stars: ✭ 82 (+355.56%)
Mutual labels:  chess-engine, chess
Demolito
UCI Chess Engine
Stars: ✭ 41 (+127.78%)
Mutual labels:  chess-engine, chess
ConvChess
Convolutional Neural Networks learns to play chess moves
Stars: ✭ 14 (-22.22%)
Mutual labels:  chess-engine, chess
uci
A thin wrapper on a uci chess engine
Stars: ✭ 33 (+83.33%)
Mutual labels:  chess-engine, chess
rustic
Rustic is a chess engine. It is written from scratch, in the Rust programming language.
Stars: ✭ 68 (+277.78%)
Mutual labels:  chess-engine, chess
littlewing
Chess engine written in Rust ♛
Stars: ✭ 27 (+50%)
Mutual labels:  chess-engine, chess
zahak
A UCI compatible chess AI in Go
Stars: ✭ 20 (+11.11%)
Mutual labels:  chess-engine, chess
magic-bits
A C++ header-only library for efficient move generation in Chess using "magic bitboards" technique
Stars: ✭ 26 (+44.44%)
Mutual labels:  chess-engine, chess
fastchess
Predicts the best chess move with 27.5% accuracy by a single matrix multiplication
Stars: ✭ 75 (+316.67%)
Mutual labels:  chess-engine, chess
elephantfish
elephantfish: 一个只有124行的中国象棋引擎
Stars: ✭ 129 (+616.67%)
Mutual labels:  chess-engine, chess
OpenChess
A cross-platform chess game.
Stars: ✭ 18 (+0%)
Mutual labels:  chess-engine, chess
chessops
Chess and chess variant rules and operations in TypeScript
Stars: ✭ 66 (+266.67%)
Mutual labels:  chess
chess.com
Python wrapper for Chess.com Published-Data API
Stars: ✭ 34 (+88.89%)
Mutual labels:  chess

Realtime-OpenCV-Chess

♔♕♗♘♙♚♛♝♞♖♜


Human vs AI (Stockfish engine)

Camera captures the image of chessboard then the images analyzed using imageprocessing to identify the moves made by opponent and stockfish engine calculates the best possible move.

opencv python

Youtube Video

check out my youtube video check out my youtube video

Image Transformation

Input-Frame warp-perspective locate-boxes
Input-Frame warp-perspective locate-boxes

Method of Working

Step - 1

Image1 : Image of Chess Board befor player move piece Image2 : Image of Chess Board after player move piece

step - 2

Difference of image by using function absdiff in CV2 Change Difference_image to Gray scale image
diff = cv2.absdiff(image1,image2) diff_gray = cv2.cvtColor(diff,cv2.COLOR_BGR2GRAY)
Difference_image Difference_image

step - 3

Apply thresholding on Grayscale image Find Contours on threshold image
matrix,thresold = cv2.threshold(diff_gray,value,255,cv2.THRESH_BINARY) cnts,_ = cv2.findContours(thresold, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
Difference_image Difference_image

Main Variables

Variables Explain
points = [] # contains chess board corners points
boxes = np.zeros((8,8,4),dtype=int) # contains top-left and bottom-right point of chessboard boxes
fen_line = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR' # fen line of chess board
board = chess.Board(fen=fen_line) # object of chess board
dir_path = os.path.dirname(os.path.realpath(file))+"/numpy_saved" # path of current directory
device = cv2.VideoCapture(1) # set devidce for read image (1: for tacking input from usb-webcam)
img_resize = (800,800) # set o/p image size
engine = chess.engine.SimpleEngine.popen_uci("stockfish-10-win\Windows\stockfish_10_x64.exe") # stockfish engine
chess_board = [] # it will store chess board matrix
bool_position = np.zeros((8,8),dtype=int) # store bool matrix of Board
number_to_position_map = [] # map move values for [0,0]-> (8,a) , [0,1]-> (8,b).... so on

Main Functions

Function Name Explain
get_points(img,n) select n points on image by double click and returns list of selected points
get_warp_img(img,dir_path,img_resize) return warp prespective of image taken by camera and resize it to img_resize value
map_function() makes a dictonary to map values { "a8":[0,0],"b8":[0,1],.... so on }
fen2board(fen_line) retuen a 8X8 matrix of chess player piece name and bool position
board2fen(chess_board) return fen line of chess board
map_function_for_number_2_position() makes a list for map values [0,0]="8a", [0,1]="8b",[0,2]="8c",... so on
rectContains(rectangle,mid_point) logic function for checking given mid_point is inside the rectangle or not
show_game(game_img,board,player_move) This function shows all game in proper format with plane turn, opponent's last move, current chess board, red and green boxes on moved piece, etc.
set_legal_positions(game_image,board,boxes) if Illegal move found in chess it shows last correct state of chess board

Author

 Vatsal Parsaniya

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].