Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D subimage detection in Open CV

What's the most sensible algorithm, or combination of algorithms, to be using from OpenCV for the following problem:

  • I have a set of small 2D images. I want to detect the locations of these subimages in a larger image.
  • The subimages are usually around 32x32 pixels, and the larger image is around 400x400.
  • The subimages are not always square, and such contains alpha channel.
  • Optionally - the larger image may be grainy, compressed, rotated in 3D, or otherwise slightly distorted

I have tried cvMatchTemplate, with very poor results (difficult to match correctly, and large numbers of false positives, with all match methods). Some of the problems come from the fact OpenCV can't seem to deal with alpha channel template matching.

I have tried a manual search, which seems to work better, and can include the alpha channel, but is very slow.

Thanks for any help.

like image 370
Sam Avatar asked Dec 31 '10 12:12

Sam


2 Answers

  1. cvMatchTemplate uses a MSE (SQDIFF/SQDIFF_NORMED) kind of metric for the matching. This kind of metric will penalize different alpha values severly (due to the square in the equation). Have you tried normalized cross-correlation? It is known to model linear variations in pixel intensities better.
  2. If NCC does not do the job, you will need to transform the images to a space where the intensity differences do not have much effect. e.g. Compute a edge-strength image (canny, sobel etc) and run cvMatchTemplate on these images.
  3. Considering the large difference in scales of the images (~10x). A image pyramid will have to be employed to figure out the correct scale for the matching. Recommend you start with a scale (2^1/x: x being the correct scale) and propagate the estimate up the pyramid.
like image 106
nav Avatar answered Nov 12 '22 06:11

nav


What you need is something like SIFT or SURF.

like image 30
Utkarsh Sinha Avatar answered Nov 12 '22 07:11

Utkarsh Sinha