Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV detect corners

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

like image 531
Linus Avatar asked Apr 24 '11 08:04

Linus


People also ask

How can you detect corner of images using OpenCV?

rectangle() function to create a rectangle around each corner. We then show the image. And this is corner detection using the goodFeaturesToTrack() method. So we can use either the Harris Corner detection method or the goodFeaturesToTrack() detection method for corner detection in Python with OpenCV.

How do I find the corners of a picture?

To detect the corners of objects in an image, one can start by detecting edges then determining where two edges meet. There are however other methods, among which: the Moravec detector [Moravec 1980], the Harris detector [Harris & Stephens 1988].

How does Harris corner detection work?

Compared to the previous one, Harris' corner detector takes the differential of the corner score into account with reference to direction directly, instead of using shifting patches for every 45 degree angles, and has been proved to be more accurate in distinguishing between edges and corners.

What is corner detection in image processing?

Corner detection works on the principle that if you place a small window over an image, if that window is placed on a corner then if it is moved in any direction there will be a large change in intensity.


2 Answers

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).

like image 79
Throwback1986 Avatar answered Oct 22 '22 17:10

Throwback1986


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.

like image 22
fdermishin Avatar answered Oct 22 '22 18:10

fdermishin