def process_files(files, basedir='./data', debug=False, rectify=False,
outdir='./data/for-labelme', **kwargs):
attempts = 0
n = len(files)
print "Rectify is set to", rectify
try:
os.makedirs(outdir)
except OSError as e:
pass
if debug:
try:
os.makedirs(os.path.join(outdir, 'debug'))
except OSError as e:
# Directory already exists
pass
for i, f in enumerate(files):
try:
newbasename = rename_file(f, basedir)
newname = os.path.join(outdir, newbasename)
print i + 1, 'of', n, newname
image = imread(f)
if rectify:
try:
meta = {}
rectified = rectify_building(image, meta)
if debug:
import pylab as pl
h = meta['homography']
pl.suptitle('u:{} d:{} l:{} r:{}'.format(h.du, h.dd, h.dl, h.dr))
pl.subplot(221)
pl.imshow(image)
pl.axis('off')
pl.subplot(222)
pl.imshow(meta['building'])
pl.axis('off')
pl.subplot(223)
h.plot_original()
pl.subplot(224)
h.plot_rectified()
pl.savefig(os.path.join(outdir, 'debug', newbasename))
imsave(newname, rectified)
except Exception as e:
print e
pass
else:
imsave(newname, image)
except Exception as e:
print e
评论列表
文章目录