GithubHelp home page GithubHelp logo

jeelchatrola / chess-playing-robotic-arm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cretus-pdpu/chess-playing-robotic-arm

0.0 0.0 1.0 7.73 MB

Robotic-Arm that can play chess

C++ 16.19% Python 83.81%

chess-playing-robotic-arm's Introduction

opencv-chess

Human vs AI (Stockfish engine)

Camera captures the image of chessboard then the imageis 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
check out my youtube video check out my youtube video

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

chess-playing-robotic-arm's People

Contributors

vatsalparsaniya avatar

Forkers

dhyeyshah28

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.