C++ 缩放和旋转模板匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10666436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:19:06  来源:igfitidea点击:

scale and rotation Template matching

c++image-processingopencvcomputer-visiontemplate-matching

提问by Storm2012

I'm using the method of match template with CV_TM_CCORR_NORMEDto compare two images ... I want to make to make this rotation and scale invariant .. any ideas?

我正在使用匹配模板的方法CV_TM_CCORR_NORMED来比较两个图像......我想让这个旋转和缩放不变......有什么想法吗?

I tried to use the same method on the fourier transform of the image and the template , but still the result after rotation is different

我尝试在图像和模板的傅立叶变换上使用相同的方法,但旋转后的结果仍然不同

回答by Larry Cinnabar

Template matching with matchTemplateis not good when your object is rotated or scaled in scene.

matchTemplate当您的对象在场景中旋转或缩放时,模板匹配效果不佳。

You should try openCV function from Features2DFramework. For example SIFTor SURFdescriptors, and FLANNmatcher. Also, you will need findHomographymethod.

您应该尝试使用Features2DFramework 中的openCV 函数。例如SIFTSURF描述符和FLANN匹配器。此外,您将需要findHomography方法。

Hereis a good example of finding rotated object in scene.

是在场景中查找旋转对象的一个​​很好的例子。

Update:

更新:

In short, algorithm is this:

总之,算法是这样的:

  1. Finding keypoints of your object image 1.1. Extracting descriptors from those keypoints

  2. Finding keypoints of your scene image 2.1 Extracting descriptors from keypoints

  3. Match descriptors by matcher

  4. Analyze your matches

  1. 1.1 寻找目标图像的关键点。从这些关键点中提取描述符

  2. 寻找场景图像的关键点 2.1 从关键点中提取描述符

  3. 按匹配器匹配描述符

  4. 分析你的比赛

There are different classes of FeatureDetectors, DescriptorExtractors, and DescriptorMatches, you may read about them and choose those, that fit good for your tasks.

有不同类别的 FeatureDetectors、DescriptorExtractors 和 DescriptorMatches,您可以阅读它们并选择适合您的任务的那些。

回答by George

Rotation invariant

旋转不变量

For each key points:

对于每个关键点:

  1. Take area around key point.
  2. Calculate orientation angle of this area with gradient or another method.
  3. Rotate pattern and request area on this angle to 0.
  4. Calculate descriptors for this rotated areas and match them.
  1. 取关键点周围的区域。
  2. 用梯度或其他方法计算该区域的方向角。
  3. 将此角度上的图案和请求区域旋转到 0。
  4. 计算这个旋转区域的描述符并匹配它们。

Scale invariant

尺度不变

See BRISKmethod

BRISK方法

回答by Tom

There are easier ways of matching a template scale and rotationally invariant than going via feature detection and homographies (if you know its really only rotated and scales, but everything else is constant). For true object detection the above suggested keypoint based approaches work better.

有比通过特征检测和单应性更简单的匹配模板尺度和旋转不变的方法(如果你知道它真的只有旋转和缩放,但其他一切都是恒定的)。对于真正的对象检测,上述建议的基于关键点的方法效果更好。

If you know it's the same template and there is no perspective change involved, you take an image pyramid for scale-space detection, and match your templates on the different levels of that pyramid (via something simple, for example SSD or NCC). It will be cheap to find rough matches on higher (= lower resolution) levels of the pyramid. In fact, it will be so cheap, that you can also rotate your template roughly on the low resolution levels, and when you trace the template back down to the higher resolution levels, you use a more finely grained rotation stepping. That's a pretty standard template matching technique and works well in practice.

如果您知道它是同一个模板并且不涉及透视变化,那么您可以使用图像金字塔进行尺度空间检测,并在该金字塔的不同级别上匹配您的模板(通过一些简单的方法,例如 SSD 或 NCC)。在金字塔的更高(= 更低分辨率)级别上找到粗略匹配将很便宜。事实上,它非常便宜,您还可以在低分辨率级别上粗略地旋转模板,当您将模板追溯到更高分辨率级别时,您可以使用更细粒度的旋转步进。这是一种非常标准的模板匹配技术,在实践中效果很好。