forked from EarlyClues/OpenQNL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
executable file
·51 lines (42 loc) · 1.45 KB
/
process.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.45 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
48
49
50
51
#!/usr/bin/env python
from PIL import Image
from optparse import OptionParser
import os
# Run this first on a video file to generate a sequence of images
# ffmpeg -i aerial.mp4 -filter:v "crop=3840,50,0,1055" -vf fps=16 tmp/out%d.png
# Usage: converts a sequence of 222 files named out1.png - out222.png
# with sliver heights of 14 pixels per image into output.png
# ./process.py -i 'out%d.png' -n 222 -y 14 -o 'output.png'
parser = OptionParser()
parser.add_option("-i", "--input", dest="filename")
parser.add_option("-o", "--output", dest="output")
parser.add_option("-n", "--num", dest="num")
parser.add_option("-y", "--height", dest="height")
options, args = parser.parse_args()
filename = options.filename or 'out%d.png'
output = options.output or 'output.png'
num = int(options.num or 100)
y = int(options.height or 50)
print filename
first_filename = filename % 1
print 'first file=%s' % first_filename
i = Image.open(first_filename)
w, h = i.size
i.close()
om = Image.new('RGB', (w, y * num))
try:
for i in xrange(1, num+1):
# Crop a 2 pixel sliver
im = Image.open(filename % i)
# Sliver in the middle of the image
top = h / 2 # h - y
crop_box = (0, top, w, top + y)
paste_box = (0, (i-1)*y, w, (i)*y)
print "i=%s copying from %s to %s" % (i, crop_box, paste_box)
r = im.crop(crop_box)
om.paste(r.rotate(180), paste_box)
except Exception, err:
print err
finally:
om.save(output)
print 'wrote %s' % output