Ask Your Question
0

Homography estimation when feature matching fails

asked 2019-10-17 13:43:31 -0600

WillTho gravatar image

Hi all,

I'm pretty new to openCV and CV in general. I want to align images of football pitches to a basic template of the pitch. I've managed to find a reasonable way of processing the full pitch images to leave me with pretty much just the pitch markings and I now have what appears to be a fairly straightforward registration problem.

I can't get it to work. I've tried orb and akaze feature matching but it doesn't work at all. Both pick up good features (mostly the curved portions like the centre circle and the D) but the matching is awful. I was using brute force matching with Hamming distance and then selecting say the top 10% of matches to estimate the homography.

What's the best approach here? I was thinking I could use a hough transform to find the centre circle in each image and match those, but the full centre circle won't always be in the target image.

Here are two example images:

Pitch template:

Reference Image

Processed image to align:

Target Image

edit retag flag offensive close merge delete

Comments

why does it fail ? don't make it so. most 2d features expect gradients and won't work on binary images. (ill-fated preprocessing)

berak gravatar imageberak ( 2019-10-17 13:51:18 -0600 )edit

and I now have what appears to be a fairly straightforward registration problem.

to a naive human, not a machine.

berak gravatar imageberak ( 2019-10-17 13:52:25 -0600 )edit

all feature2d algorithms have to look at the pixel neighbourhood of a keypoint. look at your images -- it's all zero

berak gravatar imageberak ( 2019-10-17 13:55:12 -0600 )edit
1

Thanks for taking a look! No other way using ellipse/line detection? Or a regression approach where I try to minimise the l1 norm between the images or something? Feels like there must be algorithms for registering binary images...

WillTho gravatar imageWillTho ( 2019-10-17 15:08:32 -0600 )edit

you probably could even mark the 4 points for the transformation manually.

berak gravatar imageberak ( 2019-10-17 23:51:19 -0600 )edit

I can, but I need to do this for quite a few frames so I need something automatic really. I wouldn't mind manually selecting points for the first frame and then using a sensible way to update the homography matrix from frame to frame, maybe some sort of small-motion regularisation? I don't know the names of these algorithms or how to do them in opencv, but they must be pretty common right? I just don't want to end up writing my own code to do something I can do more computationally efficiently in 1 or two lines of opencv...

WillTho gravatar imageWillTho ( 2019-10-18 03:54:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2019-12-03 08:19:18 -0600

WillTho gravatar image

I ended up coming up with a bit of a convoluted way of doing this that seems to work OK.

  • Use opencv's fast line detector with a minimum line length condition to extract the pitch markings.
  • Cluster lines (DBSCAN) based on their slope and intercept to merge detected lines that correspond to the same pitch marking.
  • Cluster lines into 'vertical' and 'horizontal' groups (k-means with k = 2 on the slopes)
  • Find the points of intersection of each vertical line segment with each horizontal line segment -- these are my features for matching. I allow some user-defined tolerance that allows segments to be extended by some number of pixels at each end.
  • Use some heuristics to match features. Stuff like using the type of intersection (T- or L-shaped) and the fact that the ordering is preserved. It's a bit of a hassle but I guess sometimes (annoyingly) you have to actually think about the problem.
  • Once the features are matched I can just use findHomography and voila.
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-17 13:43:31 -0600

Seen: 955 times

Last updated: Dec 03 '19