예제 #1
0
import glob
import os

import homography
import sift
import tic
import warp

imname = glob.glob('out_Photos/IMG_*.jpg')
siftname = [os.path.splitext(im)[0] + '.sift' for im in imname]

tic.k('start')

l, d = {}, {}
for i in range(len(imname)):
    l[i], d[i] = sift.read_or_compute(imname[i], siftname[i])

tic.k('loaded')

matches = {}
if not os.path.exists('out_ch03_pano.pickle'):
    for i in range(len(imname) - 1):
        matches[i] = sift.match(d[i + 1], d[i])
        # Slightly better matches, but ransac can handle the worse quality:
        #matches[i] = sift.match_twosided(d[i + 1], d[i])
    pickle.dump(matches, open('out_ch03_pano.pickle', 'wb'))
matches = pickle.load(open('out_ch03_pano.pickle', 'rb'))

tic.k('matched')

  p.append([c[0] + wid, c[1] - wid, c[2] + wid])
  p.append([c[0] - wid, c[1] - wid, c[2] + wid])

  # sides
  p.append([c[0] - wid, c[1] - wid, c[2] + wid])
  p.append([c[0] - wid, c[1] + wid, c[2] + wid])
  p.append([c[0] - wid, c[1] + wid, c[2] - wid])
  p.append([c[0] + wid, c[1] + wid, c[2] - wid])
  p.append([c[0] + wid, c[1] + wid, c[2] + wid])
  p.append([c[0] + wid, c[1] - wid, c[2] + wid])
  p.append([c[0] + wid, c[1] - wid, c[2] - wid])

  return numpy.array(p).T


l0, d0 = sift.read_or_compute('out_ch4pics/h_template.jpg',
                              'out_ch4pics/h_template.sift')
l1, d1 = sift.read_or_compute('out_ch4pics/h_image.jpg',
                              'out_ch4pics/h_image.sift')

#figure()
#gray()
im0 = array(Image.open('out_ch4pics/h_template.jpg'))
#sift.plot_features(im0, l0, circle=True)
#
#figure()
#gray()
im1 = array(Image.open('out_ch4pics/h_image.jpg'))
#sift.plot_features(im1, l1, circle=True)
#show()

if not os.path.exists('out_ch04_markerpose.pickle'):
imname = glob.glob('out_corner/IMG_*.jpg')
#imname = glob.glob('out_alcatraz/*.jpg')
siftname = [os.path.splitext(im)[0] + '.sift' for im in imname]

tic.k('start')

# For out_corner, this increases feature count from 4k to 16k and matches from
# 100 to 170 (which helps quality, but also slows down the program a lot, from
# from 20s to 60s):
# (with twosided matching, matches go from 85 to 113 for out_corner)
# NOTE: delete caches after changing this!
histeq = False

l, d = {}, {}
for i in range(len(imname)):
  l[i], d[i] = sift.read_or_compute(imname[i], siftname[i], histeq)

tic.k('loaded sifts')

print '{} / {} features'.format(len(d[0]), len(d[1]))
if not os.path.exists('out_ch05_recover_match.pickle'):
  #matches = sift.match(d[0], d[1])
  matches = sift.match_twosided(d[0], d[1])
  pickle.dump(matches, open('out_ch05_recover_match.pickle', 'wb'))
matches = pickle.load(open('out_ch05_recover_match.pickle', 'rb'))

tic.k('matched')

ndx = matches.nonzero()[0]
x1 = homography.make_homog(l[0][ndx, :2].T)
ndx2 = [int(matches[i]) for i in ndx]
예제 #4
0
    p.append([c[0] + wid, c[1] - wid, c[2] + wid])
    p.append([c[0] - wid, c[1] - wid, c[2] + wid])

    # sides
    p.append([c[0] - wid, c[1] - wid, c[2] + wid])
    p.append([c[0] - wid, c[1] + wid, c[2] + wid])
    p.append([c[0] - wid, c[1] + wid, c[2] - wid])
    p.append([c[0] + wid, c[1] + wid, c[2] - wid])
    p.append([c[0] + wid, c[1] + wid, c[2] + wid])
    p.append([c[0] + wid, c[1] - wid, c[2] + wid])
    p.append([c[0] + wid, c[1] - wid, c[2] - wid])

    return numpy.array(p).T


l0, d0 = sift.read_or_compute('out_ch4pics/h_template.jpg',
                              'out_ch4pics/h_template.sift')
l1, d1 = sift.read_or_compute('out_ch4pics/h_image.jpg',
                              'out_ch4pics/h_image.sift')

#figure()
#gray()
im0 = array(Image.open('out_ch4pics/h_template.jpg'))
#sift.plot_features(im0, l0, circle=True)
#
#figure()
#gray()
im1 = array(Image.open('out_ch4pics/h_image.jpg'))
#sift.plot_features(im1, l1, circle=True)
#show()

if not os.path.exists('out_ch04_markerpose.pickle'):