Live data from Hacker News

Show HN: My weekend project - Chessboard picture recognition

codebazaar.blogspot.com

11–20 of 57 posts

Re: Show HN: My weekend project - Chessboard picture recognition

#11
post #3

"For example, the program is able to determine whether each square is white or black by calculating its average color and comparing it to the black and white colors" I bet you could get away with determining the color of a corner square and assuming the rest.

Thanks for the feedback. I did not think about this.

Some of the square edges actually belongs to the surroundings squares because the cut is not 100% accurate and the chess piece are not always position at the center of the square but I could get around that.

The way this algorithm works is simple. I compare the RGB values for each pixel of a square to the black color and white color. Black is Red=0, Green=0, Blue=0 and white is Red=255, Green=255 and Blue=255. I add up the 3 RGB values for a pixel, if it is closer to 0 and 255*3, I consider the pixel is mostly black. I keep a counter of black pixels and another for white pixels.

Currently, the algo is just comparing the two counters. If I found most of the pixel were black, I consider it is a black square.

However, I could improve it as following: - > 90% of black pixels: empty black square or black square with black piece - > 90% of white pixels: empty white square or white square with white piece - other white: square with a piece of the opposite color.

For the 3rd case, I might need to implement your idea.

Re: Show HN: My weekend project - Chessboard picture recognition

#12
post #9

Hmm, interesting project. If you're ok with helping the computer out a bit, you could put a very small matrix bar code (think QR Code) on top of each piece. Since there are 6 chess pieces and 2 colors, you could have a code for each piece in just a 2x2 matrix (4 dots / bits). Otherwise, it seems like it may be very difficult, as I'm not even sure of what some of the black on black pieces are myself (bottom right).

You would have to put in some control bits/markers (like a QR code) though, since the pieces could be turned in any direction. I do agree though, it seems like you would need something to identify the pieces.

The other option, although a magnitude harder, would be to take two (or maybe three) images from a lower angle on two different sides and use that to determine the silhouette of the pieces.

Re: Show HN: My weekend project - Chessboard picture recognition

#13
post #5

For figuring out chess pieces, maybe determining the light source and looking for light/dark patterns in certain areas? The problem is, from top view, even a human would have a difficult time figuring out if a piece was a bishop or pawn.

This is true. I may need to work on a collection of pictures or even a video.

Re: Show HN: My weekend project - Chessboard picture recognition

#14
post #9

Hmm, interesting project. If you're ok with helping the computer out a bit, you could put a very small matrix bar code (think QR Code) on top of each piece. Since there are 6 chess pieces and 2 colors, you could have a code for each piece in just a 2x2 matrix (4 dots / bits). Otherwise, it seems like it may be very difficult, as I'm not even sure of what some of the black on black pieces are myself (bottom right).

I was thinking colored dots. Bar codes might look better, but wouldn't you need a pretty high resolution photo?

Re: Show HN: My weekend project - Chessboard picture recognition

#15
post #2

I don't know anything about "chess theory" but are there some squares that only certain pieces can get to? I don't think it's possible for a Knight to ever be on some squares, so maybe you could use logic like that to narrow down the piece detection. It may be easier to just track the game state from the start instead of trying to identify the position of the board at a random snapshot in time. Cool project though, s…

Thanks for leaving a comment.

"It may be easier to just track the game state from the start instead of trying to identify the position of the board at a random snapshot in time."

This is certainly true! But the original idea was to take a picture (probably from a mobile phone) and continue the game online. Taking a picture after each most is a lot of work :D

Re: Show HN: My weekend project - Chessboard picture recognition

#16
post #5

For figuring out chess pieces, maybe determining the light source and looking for light/dark patterns in certain areas? The problem is, from top view, even a human would have a difficult time figuring out if a piece was a bishop or pawn.

At least there are a lot more pawns than bishops on the field, typically. So you could easily test if the correct number of pieces were identified with a particular pair of pawn/bishop signatures.

Re: Show HN: My weekend project - Chessboard picture recognition

#17
post #2

I don't know anything about "chess theory" but are there some squares that only certain pieces can get to? I don't think it's possible for a Knight to ever be on some squares, so maybe you could use logic like that to narrow down the piece detection. It may be easier to just track the game state from the start instead of trying to identify the position of the board at a random snapshot in time. Cool project though, s…

Good point. Even though all pieces can be almost anywhere, the algorithm could use the probability of the pieces being in certain situations to improve it's guesses dramatically. This would be especially true if you told the computer whether the board was in the beginning, middle, or end game.

Re: Show HN: My weekend project - Chessboard picture recognition

#18
post #9

Hmm, interesting project. If you're ok with helping the computer out a bit, you could put a very small matrix bar code (think QR Code) on top of each piece. Since there are 6 chess pieces and 2 colors, you could have a code for each piece in just a 2x2 matrix (4 dots / bits). Otherwise, it seems like it may be very difficult, as I'm not even sure of what some of the black on black pieces are myself (bottom right).

The piece at the bottom right is a castle. I agree it is hard to see. The QR code idea is interesting.

It make me think it would be easier to recognize a domino game than a chessboard!

Re: Show HN: My weekend project - Chessboard picture recognition

#19
post #9

Hmm, interesting project. If you're ok with helping the computer out a bit, you could put a very small matrix bar code (think QR Code) on top of each piece. Since there are 6 chess pieces and 2 colors, you could have a code for each piece in just a 2x2 matrix (4 dots / bits). Otherwise, it seems like it may be very difficult, as I'm not even sure of what some of the black on black pieces are myself (bottom right).

If you can get games in machine readable format, it may be possible to develop a ML approach that figures out the most likely identifications based on relative positions and as much information as image processing provides.

Re: Show HN: My weekend project - Chessboard picture recognition

#20
post #8
post #3

"For example, the program is able to determine whether each square is white or black by calculating its average color and comparing it to the black and white colors" I bet you could get away with determining the color of a corner square and assuming the rest.

Have you seen this? http://www.illusion-optical.com/Optical-Illusions/Chessboard...

I fell for this trick. Good to know! This is one thing a computer can easily be better than a human. I make me think it could be possible to build CAPTCHAs with optical illusions.
Post reply on HN