SIFT特征提取+匹配

一. 实验要求


(1) 针对自己所处的环境,拍摄多张图片(注意要来自不同场景),构造出一个小的数据集(15张以上)。

(2) 实现数据集中,每张图片的SIFT特征提取,并展示特征点。

(3) 给定两张图片,计算其SIFT特征匹配结果。

(4)给定一张输入的图片,在数据集内部进行检索,输出与其匹配最多的三张图片。

二.实验过程

2.1 实验数据集

 

 

2.2 sift特征提取

2.2.1 源代码:


from PIL import Image
from pylab import *
from PCV.localdescriptors import sift
from PCV.localdescriptors import harris
 
# 添加中文字体支持
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:/windows/fonts/SimSun.ttc", size=14)
 
imname = 'D:/ComputerVision_code/img/sdl11.jpg'
im = array(Image.open(imname).convert('L'))
sift.process_image(imname, 'empire.sift')
l1, d1 = sift.read_features_from_file('empire.sift')
 
figure()
gray()
subplot(121)
sift.plot_features(im, l1, circle=False)
title(u'SIFT特征',fontproperties=font)
 
# 检测harris角点
harrisim = harris.compute_harris_response(im)
 
subplot(122)
filtered_coords = harris.get_harris_points(harrisim, 6, 0.1)
imshow(im)
plot([p[1] for p in filtered_coords], [p[0] for p in filtered_coords], '*')
axis('off')
title(u'Harris角点',fontproperties=font)
 
show()

2.2.2 图片特征提取结果:

 

 

2.2.3 小结

sift描述子同Harris角点算法一样,具有尺度不变性、光照不变性和旋转不变性的特点,但两个算法检测的结果能看到明显的区别,sift算法检测到的特征点明显比Harris算法的更多,更丰富,而且运算速度比较快,定位精度也比较高,体现出了sift算法特征检测的优越性。

2.3 特征匹配

2.3.1 源代码:


from PIL import Image
from pylab import *
import sys
from PCV.localdescriptors import sift
 
if len(sys.argv) >= 3:
  im1f, im2f = sys.argv[1], sys.argv[2]
else:
 
  im1f = 'D:/ComputerVision_code/img/sdl11.jpg'
  im2f = 'D:/ComputerVision_code/img/sdl12.jpg'
 
im1 = array(Image.open(im1f))
im2 = array(Image.open(im2f))
 
sift.process_image(im1f, 'out_sift_1.txt')
l1, d1 = sift.read_features_from_file('out_sift_1.txt')
 
sift.process_image(im2f, 'out_sift_2.txt')
l2, d2 = sift.read_features_from_file('out_sift_2.txt')
 
matches = sift.match_twosided(d1, d2)
print ('{} matches'.format(len(matches.nonzero()[0]))) 
 
figure()
gray()
sift.plot_matches(im1, im2, l1, l2, matches, show_below=True)
title('{} matches'.format(len(matches.nonzero()[0])))#设置子图标题
 
show()

2.3.2 匹配结果:

 

2.3.3 小结

从以上两个试验及结果可以看出sift算法匹配的精准度还是挺高的,虽然没能做到每一个特征点都对应起来(这当然也有图片角度不同,特征点不同不能找到匹配点的因素在),但是从埃菲尔铁塔的这组实验可看出,已经匹配的特征点,精准度非常高。

2.4 匹配筛选

2.4.1 输入一张数据集以外的照片:

2.4.2 匹配结果

 

2.4.3 小结

背景模糊不清晰,还有图片像素的大小会影响到sift特征点检测算法的效果;同一角度拍摄的图片匹配度会更高,但是旋转,明暗程度,图中物体尺寸的大小都不会影响到sift算法的检测效果,因此他具有较高的稳定性和准确性,以及从大量图片中检测到目标图片的高效性。

  • 5
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值