You are on page 1of 5

INTERNATIONAL SCIENTIFIC CONFERENCE

22 23 November 2013, GABROVO

OBTAIN CHESS MOVES WITH IMAGE PROCESSING


Mustafa ARDA
Trakya University

Hilmi KUU

Emir ZTRK

Trakya University

Trakya University

Abstract
Over the years, with the development of the artificial intelligence, chess became a game that is experienced a struggle
between human and artificial intelligence. Computers could detect and make counter moves to opponent's move. At this
point, chess moves detection has been have great importance. Also, chess games notation is important for later analyzes.
In this study, image processing method was used to detect chess moves in a chess match. Image processing is carried
out with the help of MATLAB Software.
Keywords: Chess Notation, Image Processing, MATLAB.

INTRODUCTION
In 1996, computer program Deep Blue,
which was built by the IBM Corporation, won
against the World Champion chess player
Garry Kasparov, it became a huge event.
Defeat of the Human intelligence in front of
the artificial intelligence caused to asking of
some questions like: Human intelligence can
be beaten by production of a human
intelligence?

In 1968, David Levy claimed that a


computer have couldnt win himself in chess
match for the coming 10 years. In 1978, he
defeated the most powerful computer
opponent in chess, but he admitted that this
situation continued no longer.
In 1996, first victory of the artificial
intelligence gained by the IBMs computer
Deep Blue. The world champion chess player
Garry Kasparov defeated by Deep Blue in two
matches, but final score was 4-2 in favor of
Kasparov. One year later, Deep Blue won the
rematch against Kasparov.
When choosing chess moves, Human and
artificial intelligent have different ways.
Humans can calculate next 50 moves
maximumly. However, computers can
calculate millions of chess moves in the same
situation.

Fig. 1. Deep Blue vs Kasparov Chess Game

Invention of the computer was a milestone


in chess playing machine history. Alan Turing,
who is founder of the computer science,
developed an algorithm that computer could
prefer chess moves according to opponents
chess moves.

Detecting a chess move is important as


deciding a chess move. Before decide a chess
move, a computer must detect the opponents
move. There are different methods for
detecting of chess moves. In this study, chess
moves detected with image processing
techniques by using MATLAB Program.

2013

EXPOSITION
The Experimental setup is shown in Figure
2. We used a chess board which has 50cm x
52cm dimensions, becomes red and white
squares and also made from the plastic
material. Chess pieces are selected black and
white colours and sticked black and white
tapes around the them to obtain contrast
difference in webcam.

In this study, we got the snapshots in


640x480 pixel resolution. Thanks to higher
resolution images, we can use more detail
pictures and analysis more data.

Fig. 3. Webcam

Chess board consists 64 squares and when


look at the whole picture, it looks like a
square. We must crop the unuseful part of
taking snapshot images, because they are in
rectangular form. For this purpose, we use the
ROI(Region of Interest) position command
which belongs to Image Acquasition Toolbox.

Fig. 2. Experimental Setup

To perceive the chess moves, we used a


webcam which has 640x480 pixel resolution.
Webcam can seen in Figure 3. The connection
of the webcam with computer is established on
USB Port. Webcam is positioned on a wooden
bracket which has 103 cm length.
Captured images from the webcam is
analyzed in notebook computer with the help
of MATLAB Program.
Image acquisition process is established
with the MATLAB Image Acquisition
Toolbox. Using this toolbox, we can adjust
the resolution, colour scale, crop and trigger of
snapshot of the taking image.

Fig. 4. Cropped Snapshot Image

There are 3 types of taking snapshot images


colour scale: Grayscale, RGB, YCbCr. Image
Acquaisition Toolbox defines the taking
snapshot images as a matrix in MATLAB
Workspace. This matrix has a 3 layer in RGB
and YCbCr format and 1 layer in Grayscale
format. In Grayscale format, every pixel has a
colour value between the 0-255 value means
black and white. Thus, taking snapshot images
converted to the digital variables. In this study,
we used the Grayscale color format.

2013

At this point, colors of chess board and


chess piecess have a really important role. To
detect chess board square and chess pieces is
very difficult when has same colour in
grayscale. For this reason, choosing chess
squares and chess pieces different colors gives
advantage to us.
After the crop process, snapshot images are
not in square matrix form. Because of that
snapshot image matrix is resized to 480x480
pixel with imresize command. Then,
snapshot image matrix is divided 64 equal
square matrix, which are consisted 60x60
square matrix, with mat2cell command.

Fig. 6. After "canny" Filtering of Snapshot Image

Figure 7 is shown the canny values


in Figure 6 snapshot image.

Fig. 7. canny Values of Snapshot Image

White lines density treshold values in


reduced 8x8 matrixs is accepted as 0,06
according to lighting and environmental
condition. After the reducing process, matrix
form shown in Figure 8.
Fig. 5. Cropped Snapshot Image in Grayscale
Format

Every one of the 64 sub-matrix elements


arithmatic mean is calculated and in this way,
snapshot image matrix is reduced from
480x480 elements to 8x8 elements. Every
element in 8x8 reduced matrix correspond to
one of the chess boards 64 squares.
To determine the which chess square has a
chess pieces, canny command will be used.
When canny command is used, transition
between black and white colors are occured a
line. Aim of using black and white stripes on
the chess pieces is helped detecting of them on
the chess board.
canny value must be between 0-1. It
describes the precision of line detection. In this
study, canny treshold value is accepted as
0,3. After the canny filtering, snapshot
image is seen in Figure 6.

Fig. 8. Reduced Form of Snapshot Image Matrix

Perception of chess moves obtain difference


between repeatedly taking 2 snapshot image
matrix. Before and after chess move,
difference between the taking snapshot image
matrix results a difference matrix. In
difference matrix, -1 element describes the
chess move begining point, 1 element
describes the chess move ending point.
In Figure 9, a chess move is shown which
is a pawn move forward 2 square.

2013

Fig. 9. Difference Matrix of First Move

Recognizing of the chess pieces are obtain


by the algorithm. Before the chess match
began, we knew all the chess pieces starting
position. Every chess pieces identfy by
numbers from 1 to 32. In Figure 10, game
matrix is shown. When chess move is made,
the movement in the difference matrix is also
happening in the game matrix. Change in the
game matrix stored in the MATLAB /
Workspace and updated in every chess move.

Fig. 11. Chessboard Notation

According to Figure 11, a notation matrix


is established and shown in Figure 12.

Fig. 12. Notation Matrix

Fig. 10. Game Matrix

In chess notation, chess pieces named with


first letter as a capital letter. Pawns have not
letter. Also a letter matrix is created and all the
capital letters of chess pieces are stored in
there. In this way, we can use letter matrix
instead of numbers from the game matrix in
chess notation. Here is the letter matrix is
shown;
Letter Matrix =
{'R';'K';'B';'K';'Q';'B';'K';'R';'';'';'';'';'';'';'';'';'';'';'';'';
'';'';'';'';'R';'K';'B';'Q';'K';'B';'K';'R'};
In chess notation, columns named letters
from a to h, rows named numbers from 1 to 8.
Chessboard notation is shown in Figure 11.

GUI (Graphical User Interface), is a subprogram of MATLAB program which contains


commands and functions are generated in
MATLAB. GUI provide user-friendly
interface. From the beginning to this point, all
image process is summed up in GUI interface.
When push the Start button, program will
start the webcam and when push the Stop
button, program will stop the webcam. After
the white chess pieces are played, White
Move button must be pushed and the black
chess pieces are played, Black Move button
must be pushed. These buttons take snapshot
images from the webcam after chess moves
are made. There are two listbox on the right of
display. When white chess pieces are played,
chess notation is seen in listbox which
White written on the top of the listbox.
Samely, when black chess pieces are played,
chess notation is seen in listbox which Black
written on the top of the listbox.
Generating GUI for this study is seen in
Figure 13.

2013

[5] Timothe COUR, Autonomous ChessPlaying Robot, Ecole Polytechnique, Page 127, 2002.
[6] G.D.Illeperuma, Using Image Processing
Techniques to Automate Chess Game
Recording, Proceedings of the Technical
Sessions Institute of Physics Sri Lanka, No:
27 , Page 76-83, 2011.
Fig. 13. Image of the Generating GUI
.

CONCLUSION

[7] kr Ozan, A Case Study on Logging


Visual Activities: Chess Game, Master Thesis,
zmir Yksek Teknoloji Enstits, 2005.

In this study, obtaining of the chess pieces


move notation with image processing
techniques is aimed and realized successfully.
Using MATLAB Program with this purpose
gives us rapid outcomes in image acquisition
and image processing steps.
Light intensity of the environment has an
influence on the recognizing of the chess
pieces. So that, changing of light intensity
directly affect the program. Because of that,
after the experimental setup position change,
the ROI Position and canny value is had to
regulate.
REFERENCE
[1] Mustafa ARDA, Grnt leme
Yntemiyle Satran Hamlelerinin Yazlmas,
Doctorate Seminar, Trakya niversitesi Fen
Bilimleri Enstits, Edirne, 2013.
[2]
http://www.bbc.co.uk/news/magazine
21876120, Access Date: 23.03.2013.
[3] Franciscus C. A. Groen, A Chess-Playing
Robot: Lab Course in Robot Sensor
Integration,
IEEE
Transactions
on
Instrumentation and Measurement, Vol. 41,
No: 6, Page 911-914, 1992.
[4] Emir Sokic, Simple Computer Vision
System for Chess Playing Robot Manipulator
as a Project-based Learning Example, IEEE,
Page 75-79, 2008.

2013

You might also like