小编Sta*_*iek的帖子

OpenCV模板匹配,多模板

我正在尝试为游戏制作机器人。基本上它从地上捡起物品,事情是这些物品有时看起来不同,例如。角度不同,或者它们躺在不同颜色的地面上等。为了使一切正常,我需要多个模板。有没有办法做到这一点?如果你不明白,请在评论中告诉我。这是我到目前为止尝试过的:

files = ["bones_{}.png".format(x) for x in range(6)]

    for i in range(6):
        img_gray = cv2.cvtColor(imageGrab(), cv2.COLOR_BGR2GRAY)
        f = str(files[i])
        template = cv2.imread(f, 0)
        w, h = template.shape[:: -1]
        res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
        threshhold = 0.70
        loc = np.where( res >= threshhold)
Run Code Online (Sandbox Code Playgroud)

这有效,但可能会更好。你有什么想法?

python templates opencv template-matching

6
推荐指数
1
解决办法
4771
查看次数

标签 统计

opencv ×1

python ×1

template-matching ×1

templates ×1