请教一下,匹配结果显示在哪里?
一般来说,模板匹配之后,需要知道以下信息: 1,模板中心点在测试图像的位置; 这个找到了: test.cpp line 246 左右: float train_img_half_width = 280/2.0f + 100; // center x,y of train_img in test img float x = match.x - templ[0].tl_x + train_img_half_width; float y = match.y - templ[0].tl_y + train_img_half_width; 但这里要x和y都要减去padding的宽度100; 不过结果仍然是整像素值,可能需进一步优化,才能得到亚像素值; 2,旋转角度值; 3,匹配相似度; 4,平移旋转齐次矩阵;
目前获取这些结果,好像都没有直接的方法;
比如:case1文件夹,不大清楚match之后,template中心点移动到train.png的什么位置了: 比方说,原始训练图像train.png,绘制了一个矩形Rect rect(120,100,280,280);然后抠图,得到模板图像,这时,模板的中心点是(120+280/2 =260, 100+280/2= 240);
采用train.png进行匹配之后,得到最相似的match,但match的x和y 并不在test.png的模板位置中心,x=225,y=205,都相差35;想了解一下,怎样才能获得匹配位置的中心点?
另外,如果采用test.png进行测试,匹配位置的中心点不大可能是整数值,想了解一下,亚像素的匹配坐标在哪里显示,或者,是否要通过 仿射变换矩阵进行 旋转平移操作,但输入中心坐标又是哪一个?谢谢
好的,谢谢
今天用case1/train.png进行训练和测试,发现匹配结果总有一个像素的出入,不大清楚哪里引起的?
init diff angle: 0 improved angle: -0.000998358 match.template_id: 30 match.similarity: 100 match position, x: 209 y: 189 src point, x: 260 y: 240.5 test_match_centre.point, x: 261 y: 241.5
其中 int roiWidth = 280; int roiHeight = 281; Rect roi(120, 100, roiWidth, roiHeight); 模板ROI区域 起点 120,100,宽度 280,281 那么模板中心点的坐标是: x=120+280/2= 260; y = 100+281/2.0 = 240.5
最好匹配结果 match.x = 209, y=189 相似度100
test_match_center是这样计算匹配模板中心: // center x,y of train_img in test img float x = match.x - templ[0].tl_x + train_img_half_width; float y = match.y - templ[0].tl_y + train_img_half_height;
结果x,y的值都大了1像素
查了下源码, 在match函数中,
match2.similarity = best_score;
match2.x = (x / T - 8 + best_c) * T + offset;
match2.y = (y / T - 8 + best_r) * T + offset;
有大量类似这样的线性运算,不大清楚是否会引入误差;
而如果ROI区域,宽和高相差较大,结果x,y会或大或小一个像素: init diff angle: 0 improved angle: -0.0801742 match.template_id: 30 match.similarity: 99.2308 match position, x: 257 y: 237 src point, x: 260 y: 190.5 test_match_centre.point, x: 261 y: 189.5
其中:ROI: (120,100,280,181)
init diff angle: 0 improved angle: -0.0560676 match.template_id: 30 match.similarity: 99.2308 match position, x: 257 y: 237 src point, x: 210 y: 240.5 test_match_centre.point, x: 209 y: 239.5
其中:ROI(120,100,180,281)
可能金字塔下采样也会带来误差,不过因为像素偏差时大时小,而且基本上都是1个像素的差值,推测可能时offset或某些线性运算造成的,能否请协助查看一下,谢谢了。
中心粗匹配误差在底层金字塔stride的一半,也就是4/2=2个pixel内。高精度需要乘ICP结果
好的,谢谢