简体   繁体   English

opencv 3.3 python linemod:如何添加模板

[英]opencv 3.3 python linemod: how to add templates

today it try to use the linemod algorithm which is part of OpenCV. 今天,它尝试使用OpenCV的linemod算法。 In an earlier C++ project I already use linemod and it works like it is described in the documentation, but this time I try to use the Python API. 在较早的C ++项目中,我已经使用linemod了,它的工作方式与文档中所描述的一样,但是这次我尝试使用Python API。

Here my approach: 这是我的方法:

import cv2

template = cv2.imread('path_to_template')

lineModDetector = cv2.linemod.getDefaultLINE()
print(len(lineModDetector.getModalities()))

mask = cv2.bitwise_not(template)[:,:,1]

ret, boundingBox = lineModDetector.addTemplate([template], "circle", mask)
print(ret)
print(boundingBox)

The template image: 模板图片:

Template Image 模板图片

But when I try to add a template it always fails. 但是,当我尝试添加模板时,它总是失败。 Has someone an idea how to make it work as expected? 有人知道如何使其按预期工作吗? I already had a look into the C++ source code but everything seems to be fine. 我已经看过C ++源代码,但一切似乎都很好。 I guess the wrapper code could be the problem?! 我猜包装器代码可能是问题吗?

Best, 最好,

Manuel 曼努埃尔

the mask is not intersect with template image. 遮罩不与模板图像相交。 even though the image is filtered by gausian, the sobel magnitude in mask area is lower than the threshold(default is 55). 即使图像被高斯滤波,遮罩区域中的sobel幅度也低于阈值(默认值为55)。 so it can't be successful. 所以它不会成功。 You can lower the threshold or just not give mask. 您可以降低阈值,也可以不设置遮罩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM