首页 > 其他 > 详细

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

时间:2021-03-29 09:12:15      阅读:30      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
import json
import os
import urllib

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

if __name__ == __main__:
    download_path = "D:\\image"
    path = "D:\\image"

    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

    # copy values
    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) + .jpg
                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) + .jpg
                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_jpg(22.jpg)

 技术分享图片

 

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

原文:https://www.cnblogs.com/aoligeia/p/14590442.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!