forked from JohnDMcMaster/xystitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opt.py
executable file
·70 lines (62 loc) · 2.21 KB
/
opt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
'''
pr0opt
.pto optimization
Copyright 2012 John McMaster
'''
import argparse
from xystitch.optimizer import PTOptimizer
from xystitch.pto.project import PTOProject
from xystitch.pto.util import *
from xystitch.linear_optimizer import *
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Manipulate .pto files')
parser.add_argument('pto_ref',
metavar='.pto reference',
type=str,
nargs=1,
help='reference project to work on')
parser.add_argument('images',
metavar='images',
type=str,
nargs='+',
help='image files to put int output')
parser.add_argument('--out',
action='store',
type=str,
dest="pto_out",
default="out.pto",
help='output file name (default: out.pto)')
parser.add_argument('--allow-missing',
action="store_true",
dest="allow_missing",
default=True,
help='Allow missing images')
parser.add_argument('--border',
action="store_true",
dest="border",
default=False,
help='Manually optimize border')
args = parser.parse_args()
pto_ref_fn = args.pto_ref[0]
pto_out_fn = args.pto_out
print 'Reference in: %s' % pto_ref_fn
print 'Out: %s' % pto_out_fn
# Have to start somewhere...
pto_out = PTOProject.from_default()
# Add the images in
for image in args.images:
pto_out.add_image(image)
pto_ref = PTOProject.from_file_name(pto_ref_fn)
pto_ref.remove_file_name()
linear_reoptimize(pto_out,
pto_ref,
allow_missing=args.allow_missing,
order=2,
border=args.border)
print 'Centering...'
center(pto_out)
print 'Converting to Hugin form...'
resave_hugin(pto_out)
print 'Saving to %s' % pto_out_fn
pto_out.save_as(pto_out_fn)