匹配地理标记图像

首先要安装graphviz和pydot,确保安装顺序正确:graphviz->grapphviz软件本身->pydot

1、安装配置Graphviz和pydot

首先要在python中安装graphviz,直接用 pip install graphviz 下载就好了。
然后下载graphviz这个软件,在官网 https://graphviz.gitlab.io/_pages/Download/Download_windows.html 直接下载msi文件进行安装,完成后打开bin文件夹,看到dot这个文件,复制它的路径,将这个路径添加到系统path中
在这里插入图片描述
在这里插入图片描述
安装和配置环境完成以后要安装pydot,直接用pip install pydot安装。
但程序仍然会有以下错误:
在这里插入图片描述
这时需要打开 python\Lib\site-packages 这个文件夹目录,找到pydot.py文件。在1712行(左Ctrl加F查找 self.prog)找到代码,原代码为self.prog = 'dot',将这行改为dot.exe所在位置,例如:
在这里插入图片描述
这样基本就完成了Graphviz和pydot的安装配置

2、匹配地理标记图像

由于图像太大曾经导致我的运行时间长到不可估计,所以我将所有的图像缩小为375*500像素,所有素材都出自集美大学尚大楼
代码如下:

from pylab import *
from PIL import Image
from PCV.localdescriptors import sift
from PCV.tools import imtools
import pydot

""" This is the example graph illustration of matching images from Figure 2-10.
To download the images, see ch2_download_panoramio.py."""

#download_path = "panoimages"  # set this to the path where you downloaded the panoramio images
#path = "/FULLPATH/panoimages/"  # path to save thumbnails (pydot needs the full system path)

download_path = "D:\Visual_Studio_Code\Code\jmu"  # set this to the path where you downloaded the panoramio images
path = "D:\Visual_Studio_Code\Code\jmu"  # path to save thumbnails (pydot needs the full system path)

imlist = imtools.get_imlist(download_path)
nbr_images = len(imlist)

featlist = [imname[:-3] + 'sift' for imname in imlist]
for i, imname in enumerate(imlist):
    sift.process_image(imname, featlist[i])

matchscores = zeros((nbr_images, nbr_images))

for i in range(nbr_images):
    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')

结果如下:
在这里插入图片描述
可以看出匹配结果很差,无法连接成一个完整的图。分析了一下原因,可能是我个人的拍摄距离较远,以及拍摄角度不是很好,加上图像缩小使得图像的像素点特征比较模糊,也有可能是尚大楼3个面(除了背面)除了楼顶部分其他部分实在太像了,尤其是两侧,很容易匹配相反或者无法连接,由于时间关系也没有再次取材,下面是取材中一些个人认为比较好看的景,学校还是很美的~
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值