Python计算机视觉 匹配地理标记图像

本文我们将使用局部描述子来匹配带有地理标记的图像:
• 输入同一场景的序列图像
• 通过SIFT算法对地理标记图像进行两两匹配,构造连接矩阵
• 可视化图像连接关系
要实现这个例子,我们首先要安装graphviz和pydot
一、graphviz和pydot的安装和配置
1.在python中安装graphviz,用 pip install graphviz 下载。
2.可以去官网 https://graphviz.gitlab.io/_pages/Download/Download_windows.html 上下载,选择graphviz-2.38.msi进行安装,在这里插入图片描述
3.安装完成后打开bin文件夹,看到dot.exe这个文件,复制它的路径,将这个路径添加到系统变量Path(计算机属性-高级系统设置-环境变量-系统变量Path)中,
在这里插入图片描述
在这里插入图片描述
4.安装pydot,直接用pip install pydot安装。
5.打开 python\Lib\site-packages 这个文件夹目录,找到pydot.py文件。找到以下代码位置(左Ctrl加F查找 self.prog)并修改,将其改为你存放的dot.exe的位置。
在这里插入图片描述
在这里插入图片描述
正常情况下,graphviz和pydot的安装配置算是完成,以上方法参考同学博客 https://blog.csdn.net/weixin_43843780/article/details/88630849

二、匹配地理标记图像
以下是代码,注意图像不能过大,我的图像尺寸为:500*375


    for j in range(i, nbr_images):  # only compute upper triangle
        print('comparing ', imlist[i], imlist[j])
        l1, d1 = sift.read_features_from_file(featlist[i])
        l2, d2 = sift.read_features_from_file(featlist[j])
        matches = sift.match_twosided(d1, d2)
        nbr_matches = sum(matches > 0)
        print('number of matches = ', nbr_matches)
        matchscores[i, j] = nbr_matches
print("The match scores is: \n", matchscores)
for i in range(nbr_images):
    for j in range(i + 1, nbr_images):  # no need to copy diagonal
        matchscores[j, i] = matchscores[i, j]

#可视化

threshold = 2  # min number of matches needed to create link

g = pydot.Dot(graph_type='graph')  # don't want the default directed graph

for i in range(nbr_images):
    for j in range(i + 1, nbr_images):
        if matchscores[i, j] > threshold:
            # first image in pair
            im = Image.open(imlist[i])
            im.thumbnail((100, 100))
            filename = path + str(i) + '.png'
            im.save(filename)  # need temporary files of the right size
            g.add_node(pydot.Node(str(i), fontcolor='transparent', shape='rectangle', image=filename))

            # second image in pair
            im = Image.open(imlist[j])
            im.thumbnail((100, 100))
            filename = path + str(j) + '.png'
            im.save(filename)  # need temporary files of the right size
            g.add_node(pydot.Node(str(j), fontcolor='transparent', shape='rectangle', image=filename))
            g.add_edge(pydot.Edge(str(i), str(j)))
g.write_png('jmu.png')

运行结果如下:
在这里插入图片描述
三、集大很美
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43848422/article/details/88675170