Rename men_at_work to water_scene, crop and zoom IMG_2412.jpg for continuity
[stop_motion.git] / div2.py
1 #!/usr/bin/env python3
2
3 import gamma
4 import numpy
5 import perspective
6 import scipy
7 import scipy.ndimage
8 import sys
9
10 sys.stderr.write(
11   '''stdin: control blocks description
12 xs0,ys0 xs1,ys1 xs2,ys2 xs3,ys3 : size (pixels)
13 xf0,yf0 xf1,yf1 xf2,yf2 xf3,yf3 : freedom (fraction of size)
14 in.jpg out.jpg x0,y0 x1,y1 x2,y2 x3,y3 : top left (pixels)
15 ...
16 '''
17 )
18
19 size = numpy.array(
20   [
21     [int(j) for j in i.split(',')]
22     for i in sys.stdin.readline().split()
23   ],
24   numpy.int32
25 ).transpose()
26 assert size.shape == (2, 4)
27 freedom = numpy.array(
28   [
29     [float(j) for j in i.split(',')]
30     for i in sys.stdin.readline().split()
31   ],
32   numpy.double
33 ).transpose()
34 assert freedom.shape == (2, 4)
35
36 files = []
37 line = sys.stdin.readline()
38 while len(line):
39   fields = line.split()
40   in_jpg = fields[0]
41   out_jpg = fields[1]
42   top_left = numpy.array(
43     [
44       [int(j) for j in i.split(',')]
45       for i in fields[2:]
46     ],
47     numpy.int32
48   ).transpose()
49   assert top_left.shape == (2, 4)
50   files.append((in_jpg, out_jpg, top_left))
51   line = sys.stdin.readline()
52
53 sys.stdout.write(
54   ' '.join(
55     [
56       ','.join([str(size[j, i] // 2) for j in range(2)])
57       for i in range(4)
58     ]
59   ) + '\n'
60 )
61 sys.stdout.write(
62   ' '.join(
63     [
64       ','.join([str(freedom[j, i]) for j in range(2)])
65       for i in range(4)
66     ]
67   ) + '\n'
68 )
69 for in_jpg, out_jpg, top_left in files:
70   sys.stdout.write(
71     ' '.join(
72       [in_jpg, out_jpg] +
73         [
74           ','.join([str(top_left[j, i] // 2) for j in range(2)])
75           for i in range(4)
76         ]
77     ) + '\n'
78   )