Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[67c31c]: src / hugin_script_interface / top_five3.py Maximize Restore History

Download this file

top_five3.py    47 lines (32 with data), 1.5 kB

 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
import hsi
# another demo plugin: this one will keep at most five control
# points per image pair. Selection is by CP error, the points
# with the smallest error are kept.
def entry ( pano , *args ) :
# this plugin doesn't take any extra arguments
if args :
print('ignoring extra arguments %s' % str(args))
# on loading the CP errors are unknown - we have to have them
# calculated before we can start:
hsi.calcCtrlPointErrors(pano)
# First we find out what pairs there are. We make a set
# of these pairs and use them as index in a dictionary
# with an empty list as value
cpv = pano.getCtrlPoints()
pairs = set ( ( cp.image1Nr , cp.image2Nr ) for cp in cpv )
cpdict = dict ( ( pair , [] ) for pair in pairs )
# now each CP goes into the list indexed by the pair of
# images it connects - but in a tuple with the error in front
# se we can easily sort by error
for cp in cpv :
cpdict[(cp.image1Nr, cp.image2Nr)].append((cp.error, cp))
# we extract the five values with the smallest error
# from every list. The CPs in there are our top five,
# so we put them into cpv
cpv = []
for pair in pairs :
top_five = [ t[1] for t in sorted(cpdict[pair])[:5] ]
cpv.extend ( top_five )
# finally we attach the new CP vector to the panorama
pano.setCtrlPoints ( cpv )
return 0