Webcam + Go

For discussing go computing, software announcements, etc.
User avatar
Phelan
Gosei
Posts: 1449
Joined: Tue Apr 20, 2010 3:15 pm
Rank: KGS 6k
GD Posts: 892
Has thanked: 1550 times
Been thanked: 140 times

Re: Webcam + Go

Post by Phelan »

GregA wrote:Very impressive! I've put my project on a hold a bit as my work has heated up lately, but I plan to put my code up on an opensource site like google code and do some more work on it. I've mostly focused on the problem of automatically detecting a board from a single image, regardless of how many stones are on it - and at as low of an angle as possible. As I'm sure you've noticed, it's not an easy problem. With lots of stones on the board, you have to rely on the edges of the board, and it's easy to find false edges. And at low angle, you have to be very accurate or it is very difficult to accurately find which stones are on which intersection.


I've heard of two approaches for this, trying to find the corners and extrapolate stone position, or the opposite, find stones, and extrapolate the board position from it. Have you tried the second?
(disclaimer: I know very little about computer vision algorithms)
a1h1 [1d]: You just need to curse the gods and defend.
Good Go = Shape.
Associação Portuguesa de Go
smiladon
Beginner
Posts: 2
Joined: Sat May 22, 2010 3:29 am
Rank: KGS 10 kyu
GD Posts: 0
Been thanked: 1 time

Re: Webcam + Go

Post by smiladon »

Hi
I got this thread recommended from a friend. We have written a goboard detection algorithm in a coarse called "statistical image analysis" which does almost the same, but for still images. Maybe we can exchange some ideas.

We use matlab since we are more into math then programming. Our code takes a single image and find the board, gridlines and stones and combine them to find coordinates. Our thought was to use the laptop as a go-clock where you take a picuture from a webcam each time the turn is handed over to the other player.

Our filters are far from optimal and we cannot detect the board in hard backgrounds as in your youtube video where the edges of the table is more distinct then the edges of the board against the table.

I attached a pdf with our basic idea of getting the coordinates.

/Viktor
flowchart.pdf
Idea of extracting coordinates
(466.72 KiB) Downloaded 1579 times


Here is a link to some picture that we used to evaluate the performance. 2 of the pictures taken miss a grid line and therefor generate a wrong board position. 1 Did just get 18 gridlines in one direction detected and therefor crashed. This can be improved and i am trying to figure out how.
http://dl.dropbox.com/u/998131/result.zip
SebastianR
Beginner
Posts: 6
Joined: Wed May 19, 2010 12:57 pm
Rank: 100 kyu
GD Posts: 0
Been thanked: 4 times

Re: Webcam + Go

Post by SebastianR »

Hi smiladon,
nice chart and indeed your separation of edges and lines is something I haven't considered so far. How did you do that? I guess you applied a black top hat filter? Anyways I will try that because the edges and their shadows are the most annoying thing for me right now. Other than that, my board detection works very much like yours. I make a hough transformation get regional maxima and try to combine them to a squared grid. This is done in a quite unmathematical way but its not very sensitive to other edges in the picture.
In detail I start with a bright point and find the brightest neighbor. Then I extend the line by the distance of the two points in both directions, add the brighter "end" and calculate a line closest to the three points (regression) and so on until no more points are found in hough space on that line (i also check that the distance of two points is a somewhat monotone function. In the end I project every point added this way on the regression line. this way I end up with a grid that matches the original quite good. This is neccessary because I use the grid to triangulate camera position and - using camera position and a height for the stones to be placed - project the center of stones that are placed on intersections back to the picture (where i can check if there are color values other than board color in that place).
As you can see that relies heavily on getting the exact (hough) parameters for the grid. Am I right that you also need an almost empty board to detect the grid and cannot infer that from the stones you see? Because otherwise you would not know what line is the closes the the stone (if there are no lines to see). And what about low angles when the brightest point of a white stone is closer to a line that is further away?

I find it quite funny that even this, what might be the easiest task there is in image processing, is causing so much trouble :-)


Added
Nice results. Its working perfectly in the beginning but just like me, fails when the lines are barely visible or totally covered. You might extend the working time by 100 moves or so by interpolating missing lines but in the end there are almost no more lines left to see :-(
By that time one could just consider earlier used parameters fixed and hope for the best but thats not satisfactory (or satisfying? sorry im no native speaker *g*)
smiladon
Beginner
Posts: 2
Joined: Sat May 22, 2010 3:29 am
Rank: KGS 10 kyu
GD Posts: 0
Been thanked: 1 time

Re: Webcam + Go

Post by smiladon »

filtering the image for edge and board are done with opening and closing operation. Filters were designed by my partner so will cite our report:
In order to find the board several different filters were used. First the contrast was adjusted to increase the difference between go-board and background. Second, a closing-filter was used. The closing operation is a morphological dilation, followed by a erosion [matlab-help]. This emphasizes brighter regions of the board and removes small, dark regions entirely.

The third operation was a standard 3x3 averaging filter followed by a 3x3 sobel edge detection filter. Since the closing operation and the averaging filter removed the grid lines on the board, as well as most irregularities, the sobel edge detection filter primarily emphasizes the edges of the go board


and for grid lines
The sequence of filters employed in order to find the grid lines of the go board is similar to that which was used to find the edges. From the original image two different images were created. The first was generated by a closing operation and the second by an opening operation, which emphasizes darker regions, such as the black grid lines.

The lines themselves are found by taking the absolute difference between the two filtered images. The result, after applying a threshold using Otsu's method [matlab-help], can be seen in figure [fig-grid].


We dont see any increasing difficulty in finding the board when adding stones. We use the the information of the board edges to limit the search region for grid lines, and it works pretty well even on crowded boards, but as i said it does not work perfect and I are considering ways to improve it.
Detecting gridlines on a halffull board
Detecting gridlines on a halffull board
Result_2010-05-18-140450.jpg (95.44 KiB) Viewed 38546 times


At the level of stones on the board above it works well in 27 out of 30 images, and i belive i can make it work at even higher rate. The result is good enough for the coarse and therefor i will focus on other task until this semester is over (10 more days), then i might work some more on this project =)
xed_over
Oza
Posts: 2264
Joined: Mon Apr 19, 2010 11:51 am
Has thanked: 1179 times
Been thanked: 553 times

Re: Webcam + Go

Post by xed_over »

smiladon wrote:img- captured stones: 1 black and 7 white

nice work, but I find it funny that you even bother to count the captured stones from the picture off the board.

they are not needed for the final score, and even if you think you still need them, you can simply count the stones on the board. (and it also doesn't matter the number of moves played, because 1b and 7w stones is the same as 0b and 6w stones in the final score)
User avatar
GregA
Beginner
Posts: 15
Joined: Fri Apr 23, 2010 2:03 pm
Rank: KGS 8 kyu
GD Posts: 0
Location: Seattle, WA, USA
Been thanked: 4 times

Re: Webcam + Go

Post by GregA »

SebastianR wrote:Thx greg,
were you successful with that? Right now, I don't have any idea on how to recognize a board full of stones other than brute force.
And because the picture of the board is a "function" of 4 (important) variables (2 rotations and 2 translations) that would take forever.
And additionally, in very low angles half the lines - the horizontal - become useless because they have nothing to do with where the stone is seen. And
in resolutions for realtime image processing they are barely seeable even when the board ist empty. Also the stones become ellipses and when covered by other stones
"in front" of them their form is something even more irregular. I tried my program and it would work with angles as low as 25 to 30 degrees but only when properly set up (with stones in the corner).
But on the other hand, I have only experience with that one approach of detection...
Maybe your good with only taking the two most dominant lines, guessing the camera parameter and interpolating the rest of the grid


I'm using OpenCV, which gives a lot of useful computer vision algorithms. First I convert to gray, then dilate (to erase the lines on the board, actually), then canny to get the edges, then houghlines to find dominant lines. If I then pick the right 4 lines at this point, my code usually does fine, but sometimes there are a lot of extra lines that confuse things. My next step, actually, is to get a bunch of sample images and tune my algorithm for choosing the board boundary lines.

Once I have the lines, I get the corners, pass that to GetPerspectiveTransform to get my transform, and WarpPerspective to give me a square image to check for stones.

There's a trick from one of the papers I mentioned in one of the threads on GD, where once you find the corners of the board, you then adjust them to get the corners of a rectangle floating roughly half a stone height above the board. There's still the issue of overlapping stones as you say - in the view warped to a square, stones stretch out and overlap quite a lot. Clearly at some angle between 45 and 0 degrees everything breaks down and difficulty of finding stones jumps to impossible.

At the moment, I ignore the lines entirely, and I try to ignore the stones too, when finding the board corners. This seems to me to be throwing out too much information. It seems to me an ideal algorithm would try to use all available information. I've been working on selecting lines using the knowledge that boards are roughly square, likely to be in the center of the image, and at an angle greater than 20 degrees or so (because I can't do anything with really low angle images, anyway). But it would be nice to also take into account the fact that boards tend to be roughly a specific color, with a black grid filling some portion of it. And the portions that don't have a grid should have filled ellipses that are either black or white. And the shape of the ellipses is tied to the angle, which, in turn, is tied to the specific boundary lines being considered - all in an interconnected feedback loop.

It would be nice to be able to combine this information somehow in a board probability map immage, where pixels that seem like part of a board are given a high score. This could then be processed with some mathematical morphology tricks to get areas that are likely to contain board edges. This would then be fed to the hough line selection code.

And then, after finding a best choice of boundary lines, the corners could be micro-adjusted. A given set of corners implies a grid floating above the board where stones could be found, and it implies a grid on the board where gridlines could be found. By shifting the corners around, you could explore the state space and try to improve the grid and stone detection until you reach the best fit.

At the moment, I do some brain-dead simple stone detection that is easily fooled by glare on the board - in the warped image, go to the expecte intersection point and search within a small circle, classifying pixels as white/black/board, and then pick the highest count. I'd like to make a stone detector that knows the camera angle and therefore the expected stone shape - it should also be able to know where the gridlines should be expected if there is no stone. Then there is whole-board knowledge, which would be nice to take into account - if there are some problematic intersections that I can't decide if they're white stones or open board, I should be able to compare with areas that I more easily detected either white stones or open board. There are a bunch of tricks to adjust for lighting artifacts, but unfortunately they involve looking at average brightnesses of larger areas. That seems like a big problem - white stones surrounded by black stones or white stones or board would have very different average regional brightnesses.

Anyway, I've been very busy with work, so I haven't been able to touch the code for a while, but I look forward to doing some more work on it - and putting it all up on some opensource hosting site for others to play with.
User avatar
GregA
Beginner
Posts: 15
Joined: Fri Apr 23, 2010 2:03 pm
Rank: KGS 8 kyu
GD Posts: 0
Location: Seattle, WA, USA
Been thanked: 4 times

Re: Webcam + Go

Post by GregA »

I should add that my next step actually was to try to gather a large collection of images and corresponding sgf files. I could then build a database with the "correct" board corners, and then I could have a test suite that runs each portion of my code through the whole set and generates a report of success/failure/confidences.

Ideally, it would be a lot of different boards, different stones, different tables, different backgrounds, different lighting conditions, different camera angles, and at varying points in the games.

Maybe this is something we should collaborate on building/sharing?
User avatar
Phelan
Gosei
Posts: 1449
Joined: Tue Apr 20, 2010 3:15 pm
Rank: KGS 6k
GD Posts: 892
Has thanked: 1550 times
Been thanked: 140 times

Re: Webcam + Go

Post by Phelan »

Have you thought about using sun xi's screensaver to take shots of boards from various angles while it replays a game?

It wouldn't be the same as an actual game, but it might help you get more test cases fast, since it might even be automatable.
a1h1 [1d]: You just need to curse the gods and defend.
Good Go = Shape.
Associação Portuguesa de Go
bccwuho
Beginner
Posts: 2
Joined: Tue Jan 04, 2011 8:32 am
Rank: 3d
GD Posts: 0

Re: Webcam + Go

Post by bccwuho »

Hi, all:

The megaupload link doesn't work now. Does anyone can share this application again? Thanks.

Best Regards,

Joe
User avatar
Li Kao
Lives in gote
Posts: 643
Joined: Wed Apr 21, 2010 10:37 am
Rank: KGS 3k
GD Posts: 0
KGS: LiKao / Loki
Location: Munich, Germany
Has thanked: 115 times
Been thanked: 102 times

Re: Webcam + Go

Post by Li Kao »

I think it was this program.

@SebastianR If you want it removed, just message me
Attachments
GoRecorder.zip
(347.5 KiB) Downloaded 743 times
Last edited by Li Kao on Thu Jan 06, 2011 6:22 am, edited 1 time in total.
Sanity is for the weak.
bccwuho
Beginner
Posts: 2
Joined: Tue Jan 04, 2011 8:32 am
Rank: 3d
GD Posts: 0

Re: Webcam + Go

Post by bccwuho »

Thanks.
kaneda.dry
Beginner
Posts: 1
Joined: Wed Nov 23, 2011 6:54 am
Rank: FFG 16K
GD Posts: 0
KGS: kaneda75

Re: Webcam + Go

Post by kaneda.dry »

Hi,

As I understood, there is several project on the same subject
- one from SebastienR
- one from GregA
- one from smiladon
But no news since May 2010

I found also www.gowatcher.com but no news since December 2009.

I am very interested into this project to record go games for tournament of my go club.
I am a software developper (mostly in C) but I admit that I am not very good in image processing.
I have a lot of ideas to make a complete soft with many cool functionalities.

So I'm looking for an open source project to continue it (and keep it free). If you have any code to share with me, please do it :) I think you stopped your project so maybe they can reborn with my help.

Thanks
Tony
pasky
Dies in gote
Posts: 43
Joined: Wed Apr 21, 2010 6:49 am
Has thanked: 4 times
Been thanked: 22 times

Re: Webcam + Go

Post by pasky »

Hi! A student of mine, Tomas Musil, has created open source Go board optical recognition software that seems pretty nicely usable. We have focused on completely automatic runs, so it automatically detects the board corners and then the stones on the board. You can find it at http://tomasm.cz/imago together with a lot of pictures, documentation and bachelor thesis describing the algorithms in detail.
Go programmer and researcher: http://pasky.or.cz/~pasky/go/
EGF 1921, KGS ~1d and getting weaker
User avatar
quantumf
Lives in sente
Posts: 844
Joined: Tue Apr 20, 2010 11:36 pm
Rank: 3d
GD Posts: 422
KGS: komi
Has thanked: 180 times
Been thanked: 151 times

Re: Webcam + Go

Post by quantumf »

Imago is pretty impressive, I must say. Auto-detecting perspective and rotation is very nice. I will say that the solution needs a fair amount of work before it's viable as a commercial offering - it is currently overly sensitive to lighting contrast. For instance, this image

light.jpg
light.jpg (229.9 KiB) Viewed 15676 times


results in this - pretty good import, except for the highly illuminated patch in the top middle.

Click Here To Show Diagram Code
[go]$$c Imago import.
$$ ---------------------------------------
$$ | . . . . . . . . . . . . . . . . . . . |
$$ | . . . . . . . . O O . . . . . . . . . |
$$ | . . . O . . . O O O O O O O O . . . . |
$$ | . . . X . . . O O O O O X X X O O O . |
$$ | . . . . . . . . O O O . O . X X X X . |
$$ | . . . . . . . . . . . O O X . . . O . |
$$ | . . . . . . . . . . . X X O X X X O . |
$$ | . . . . . . . . . . . . . O O O O O . |
$$ | . . . . . . . . . . O . . . . . X X . |
$$ | . . . . . . X X . X X X X . . X . O . |
$$ | . . . . . . . O X . X O . . . . . . . |
$$ | . . . . . O . O O O O O X X X . . . . |
$$ | . . . . . . . . O X O . O . . . . . . |
$$ | . . X . . . . X X X O . O X X O O . . |
$$ | . . . . . . . . . . X X X O O O X . . |
$$ | . . . X . . . X X . . . O O . X X . . |
$$ | . . . . . O . O O . O . O X . . . . . |
$$ | . . . . . . . . . . . O X X . X . . . |
$$ | . . . . . . . . . . . . . . . . . . . |
$$ ---------------------------------------[/go]


On the other hand, this darker image
dark.jpg
dark.jpg (258.28 KiB) Viewed 15676 times


results in a complete failure.

Click Here To Show Diagram Code
[go]$$c Imago import.
$$ --------------------------------------- |
$$ | X . O . X X X X X X X X X X X X O . O |
$$ | O X . X X X . X . X . X . X . X X X X |
$$ | O . X X X . O O O . O . O O O . X X X |
$$ | X X X X X . O . . . X . O . . . X X X |
$$ | X X X X X . O . X X X X X X X X X X X |
$$ | X X X . . . O . X . X . X . X . X X X |
$$ | X X X O O O O X X . X X X X X X X X X |
$$ | X . O . . . . . X . X . . . . . . . X |
$$ | X . O . X X X X X X X X . . . . X X X |
$$ | O . . . . . X . . . . . O . O . O . X |
$$ | O O O O O . X . O O O O O O O O O . X |
$$ | . . O . O . X . O . . . . . X . O . . |
$$ | . . X X X . O O O . X . . X X . O . X |
$$ | . . X . . . O . O . X . . . X . O . . |
$$ | O O O . X X X X X X X . . X X . O . X |
$$ | . . O . . . . . . . . . . . . . O . . |
$$ | O O X . O O O O O . O . . O O O O . O |
$$ | O . X . O O O . O . O . . O O . O . O |
$$ | . . X . . . . X X . . . . O O X X X X |
$$ ---------------------------------------[/go]
pasky
Dies in gote
Posts: 43
Joined: Wed Apr 21, 2010 6:49 am
Has thanked: 4 times
Been thanked: 22 times

Re: Webcam + Go

Post by pasky »

Hi! Thanks for the feedback, nice testcases. Indeed, a lot of improvement will be probably needed for many uses, mainly more sophisticated stone detection I guess. (Then again, for some uses like automatic tournament game transmission where you can set things up a bit, I think Imago might be almost good enough as it is now now.)

I'm not sure if Tomas has any plans for making a commercial offering out of this; I certainly don't. :-) But maybe having free, working codebase as a starting point might help someone to build one.
Go programmer and researcher: http://pasky.or.cz/~pasky/go/
EGF 1921, KGS ~1d and getting weaker
Post Reply