This is a topic that I keep coming back to. This time for Chess. The goal is to extract chess notation for a game played in view of a webcam. This time I made it harder for myself by viewing the board from an angle. I wrote it in Groovy using platform-independent JAI (Java Advanced Imaging). I've cheated on the webcam capture, and used Photo Booth stills to begin with. This time, though, I'm sharing the code on GitHub.
For each frame I do the following:
1. Convert to grayscale using "bandcombine":
2. Correct for perspective using PerspectiveTransform.getQuadToQuad and "warp": (I noted the pixel coordinates for the corners of the board by hand)
3. Binarize upper and lower bands of the image histogram and OR them together (so that a white pixel ideally identifies the presence of a piece on the board) -- using "histogram", "binarize", OrDescriptor, and SubtractDescriptor:
Then I take each processed frame and its following processed frame, and do the following:
1. XOR the two frames using XorDescriptor:
2. Erode the result using "erode":
3. Open it using "dilate" and then "erode":
The result would ideally show clusters of pixels in the board squares that have changed (e2 to e4 in this example). Unfortunately, a naive solution here isn't enough as pieces span multiple board locations. Also the piece detection algorithm in step 3 of frame processing is too weak.
Feel free to ask questions if you're interested.
Jul 22, 2011
Chess Board Computer Vision
Subscribe to:
Post Comments (Atom)
5 comments:
Hello,
I just started watching your project on GitHub. I still need to take a look at the existing code to understand what you are doing but I'm curious to ask; are you using any Canny Edge detection? Could it be useful to determine the board squares and their position(s)?
Hi Erik,
My codebase has changed to focus on a 2D view of the board (i.e. from above). It's also somewhat OSX dependent (OSX speech, and wacaw for webcam capture). I've been slacking a bit at pushing my code to github, so what's there may be behind.
Cheers,
Merlyn
Oh. And I'm not using edge detection at all with the latest evolution of my solution.
O ok. I might want to pull a copy and play around with it a little bit. I haven't done any implementation with Groovy before though. Can you recommend an IDE to start with?
IDEA works fine.
Post a Comment