def find_similar(imagenames, plot_features=False): '''Find similar images pairs ''' first_figure = True images = [ MyImage(i) for i in imagenames ] matches = defaultdict(list) length = len(images) if plot_features: for image in images: if first_figure: first_figure = False else: pylab.figure() sift.plot_features(image.im, image.locs, circle=True) for i in range(length): this = images[i] print 'Find match for', this.filename, ' ', for j in range(i+1, length): that = images[j] sys.stdout.write('.') sys.stdout.flush() matched_points = nn.match_twosided(this.desc, that.desc) similarity = sum(matched_points > 0) matches[i].append((similarity, j, matched_points)) matches[j].append((similarity, i, matched_points)) print ' ', # at least 10 points matched # and only need top 3 matches scores = sorted([k for k in matches[i] if k[0] > 10 ], reverse=True)[:3] if not scores: print 'No match :(' else: for sim, k, matched_points in scores: that = images[k] print '%s(%d) ' % (that.filename, sim), if first_figure: first_figure = False else: pylab.figure() if k < i: # only cal the top right triangle this = images[k] that = images[i] sift.plot_matches(this.im, that.im, this.locs, that.locs, matched_points) print pylab.show()
def find_similar(imagenames, plot_features=False): '''Find similar images pairs ''' first_figure = True images = [MyImage(i) for i in imagenames] matches = defaultdict(list) length = len(images) if plot_features: for image in images: if first_figure: first_figure = False else: pylab.figure() sift.plot_features(image.im, image.locs, circle=True) for i in range(length): this = images[i] print 'Find match for', this.filename, ' ', for j in range(i + 1, length): that = images[j] sys.stdout.write('.') sys.stdout.flush() matched_points = nn.match_twosided(this.desc, that.desc) similarity = sum(matched_points > 0) matches[i].append((similarity, j, matched_points)) matches[j].append((similarity, i, matched_points)) print ' ', # at least 10 points matched # and only need top 3 matches scores = sorted([k for k in matches[i] if k[0] > 10], reverse=True)[:3] if not scores: print 'No match :(' else: for sim, k, matched_points in scores: that = images[k] print '%s(%d) ' % (that.filename, sim), if first_figure: first_figure = False else: pylab.figure() if k < i: # only cal the top right triangle this = images[k] that = images[i] sift.plot_matches(this.im, that.im, this.locs, that.locs, matched_points) print pylab.show()
# -*- coding: utf-8 -*- from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image dsift.process_image_dsift('gesture/empire.jpg', 'empire.dsift', 90, 40, True) l, d = sift.read_features_from_file('empire.dsift') im = array(Image.open('gesture/empire.jpg')) sift.plot_features(im, l, True) title('dense SIFT') show()
# -*- coding: utf-8 -*- from PCV.localdescriptors import sift, dsift from pylab import * from PIL import Image dsift.process_image_dsift('../data/empire.jpg','empire.dsift',90,40,True) l,d = sift.read_features_from_file('empire.dsift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im,l,True) title('dense SIFT') show()
from PIL import Image from pylab import * from numpy import * from PCV.localdescriptors import dsift, sift """ This is the dense SIFT illustration, it will reproduce the plot in Figure 8-2. """ dsift.process_image_dsift('../data/empire.jpg', 'empire.sift', 90, 40, True) l, d = sift.read_features_from_file('empire.sift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im, l, True) show()
im1f, im2f = sys.argv[1], sys.argv[2] else: im1f = '../data/sf_view1.jpg' im2f = '../data/sf_view2.jpg' # im1f = '../data/crans_1_small.jpg' # im2f = '../data/crans_2_small.jpg' # im1f = '../data/climbing_1_small.jpg' # im2f = '../data/climbing_2_small.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') figure() gray() subplot(121) sift.plot_features(im1, l1, circle=False) #sift.process_image(im2f, 'out_sift_2.txt') l2, d2 = sift.read_features_from_file('out_sift_2.txt') subplot(122) sift.plot_features(im2, l2, circle=False) #matches = sift.match(d1, d2) 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) show()
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 = '../data/empire.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(131) sift.plot_features(im, l1, circle=False) title(u'SIFT特征', fontproperties=font) subplot(132) sift.plot_features(im, l1, circle=True) title(u'用圆圈表示SIFT特征尺度', fontproperties=font) # 检测harris角点 harrisim = harris.compute_harris_response(im) subplot(133) 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)
from PIL import Image from pylab import * from numpy import * from PCV.localdescriptors import dsift, sift """ This is the dense SIFT illustration, it will reproduce the plot in Figure 8-2. """ dsift.process_image_dsift('../data/empire.jpg', 'empire.sift', 90, 40, True) l,d = sift.read_features_from_file('empire.sift') im = array(Image.open('../data/empire.jpg')) sift.plot_features(im, l, True) show()
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 = '../data/empire.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(131) sift.plot_features(im, l1, circle=False) title(u'SIFT特征',fontproperties=font) subplot(132) sift.plot_features(im, l1, circle=True) title(u'用圆圈表示SIFT特征尺度',fontproperties=font) # 检测harris角点 harrisim = harris.compute_harris_response(im) subplot(133) 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)