首页 > 解决方案 > 模板匹配 - 在 GUI 上匹配绘制形状

问题描述

我正在研究模板匹配使用实现的功能在它们之间建立匹配空间并获得原始照片中预期匹配的局部最大值

现在,我将局部最大值 x , y 显示在列表中

在我的 GUI 中,我想在局部最大值点周围绘制一个矩形或一个圆圈,在检测到的模式标签中显示它们(原始图像的灰度与检测到的形状上的矩形),如下所示

图形用户界面示例

矩形和圆形的两个函数,当我已经在 GUI 的标签上显示图像时,如何连接这两个函数以围绕局部最大值点绘制,这样局部最大值点被取并用作中心在标签上显示的图像上的矩形除了那些功能与 matplot 我希望它们在 GUI 中标签上已经存在的图像上

def make_rects(plt_object,xy,template):
        htemp, wtemp = template.shape
        for ridx in range(xy.shape[0]):
            y,x = xy[ridx]
            r =  plt.Rectangle((x-wtemp/2, y-htemp/2), wtemp, htemp, edgecolor='g', facecolor='none')
            plt_object.add_patch(r)

    def make_circles(plt_object,xy,template):
        htemp, wtemp = template.shape
        for ridx in range(xy.shape[0]):
            y,x = xy[ridx]
            plt_object.plot(x, y, 'o', markeredgecolor='g', markerfacecolor='none', markersize=10)

这是我实现的功能

 import numpy as np
 from scipy.signal import correlate2d

        def match_template_corr(x, temp):
            y = np.empty(x.shape)
            y = correlate2d(x, temp, 'same')
            return y

界面图片: 在此处输入图像描述

标签: pythonimagefunctionuser-interfaceimage-processing

解决方案


推荐阅读