shape_based_matching icon indicating copy to clipboard operation
shape_based_matching copied to clipboard

矩形模板匹配

Open DaxiongAI opened this issue 4 years ago • 15 comments

image image

大佬,模板匹配时当匹配图像角度很小接近0°时特征点非常少,如上图,模板制作时也是同样情况.

DaxiongAI avatar Apr 06 '21 06:04 DaxiongAI

最少点数设的多少?

meiqua avatar Apr 06 '21 13:04 meiqua

num_features:200

DaxiongAI avatar Apr 07 '21 02:04 DaxiongAI

代码用的最新的吗?同样的图像,不是0度模板就正常了?

meiqua avatar Apr 07 '21 11:04 meiqua

代码用的最新的,是的,当模板有角度时特征点很多,如下图: image

DaxiongAI avatar Apr 07 '21 13:04 DaxiongAI

有意思。可以把原图跟复现代码给出来吗?

meiqua avatar Apr 07 '21 15:04 meiqua

代码用的test.cpp:noise_test,模板原图如下: image

DaxiongAI avatar Apr 08 '21 07:04 DaxiongAI

直接在master branch上试了下,把detector num features 30改成200,0度也正常呀。

meiqua avatar Apr 08 '21 14:04 meiqua

直接在master branch上试了下,把detector num features 30改成200,0度也正常呀。 特征点少是因为num features设置的少吗?

wly2020-robot avatar Apr 09 '21 01:04 wly2020-robot

找到问题了,我设置模板角度是-20~20度,只用求一次特征点,其余角度旋转特征点就行.

if (info.scale != scale) {
        templ_id = detector.addTemplate(shapes.src_of(info), class_id, shapes.mask_of(info), num_features * info.scale);
        first_id = templ_id;
        first_angle = info.angle;
        scale = info.scale;

      } else {
        templ_id = detector.addTemplate_rotate(class_id, first_id,
                                               info.angle - first_angle,
                                               {shapes.src.cols / 2.0f, shapes.src.rows / 2.0f});
      }

DaxiongAI avatar Apr 13 '21 09:04 DaxiongAI

还有个问题,demo的识别结果特征点是很准确的分布在边缘,但矩形框位置有偏差,大佬,是我方式不对吗?

      int x = templ[0].width + match_x;
      int y = templ[0].height + match_y;
      cv::rectangle(test_img, {match.x, match.y}, {x, y}, randColor, 2);

image

DaxiongAI avatar Apr 13 '21 09:04 DaxiongAI

这个框看上去挺好的呀,就是大了一圈

meiqua avatar Apr 13 '21 12:04 meiqua

对呀,大了,我想提取边缘中心,这咋整,是我画的方式不对吗?特征点位置很准确,矩形框会大一些.

DaxiongAI avatar Apr 13 '21 13:04 DaxiongAI

可以调用cv::minAreaRect

meiqua avatar Apr 15 '21 05:04 meiqua

直接在master branch上试了下,把detector num features 30改成200,0度也正常呀。 特征点少是因为num features设置的少吗?

你好 我在master branch测试angle_test, 没有很好的匹配上,知道是什么原因吗

mo704507064 avatar Apr 08 '22 07:04 mo704507064

@DaxiongAI @mo704507064 可以參考下我寫的NCC-Based模板匹配,角度精度測試與Cognex-Pat Quick差不多 https://github.com/DennisLiu1993/Fastest_Image_Pattern_Matching

DennisLiu1993 avatar May 12 '22 14:05 DennisLiu1993