6
votes

I'm using OpenCV on the iPhone. I want to find a Sudoku in a photo. I started with some Gaussian Blur, Adaptive Threshold, Inverting the image and Dilate. Then I did some findContour and drawContour to isolate the Sudoku grid. Then I've used the Hough Transform to find lines and what I need to do now is find the corners of the grid. The Sudoku photo may be taken in an angle so I need to find the corners so I can crop and warp the image correctly.

This is how two different photos may look. One is pretty straight and one in an angle:

Probabilistic Hough

http://img96.imageshack.us/i/skrmavbild20110424kl101.png/

http://img846.imageshack.us/i/skrmavbild20110424kl101.png/

(Standard Hough comes in a comment. I can't post more than two links)

So, what would be the best approach to find those corners? And which of the two transform is easiest to use?

Best Regards Linus

2

2 Answers

2
votes

Why not use OpenCV's corner detection? Take a look at cvCornerHarris().

Alternatively, take a look at cvGoodFeaturesToTrack(). It's the Swiss Army Knife of feature detection and can be configured to use the Harris corner detector (among others).

1
votes

I suggest the following approach. First, find all intersections of lines. It is helpful to sepparate lines into "horisontal" and "vertical" by angle (i.e. find two major directions of lines). Then find the convex hull of acquired points. Now you have corners and some points on the boundaries. You can remove the latter by analysing the angle between neighbour points in the convex hull. Corners will have the angle about 90 degrees and points on the boundaries - about 180 degrees.