command line option for avi output in turing.py
This commit is contained in:
parent
848fa23a07
commit
2a19db61e7
@ -6,9 +6,26 @@ Inspired by http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Pa
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2, cv
|
import cv2, cv
|
||||||
from common import draw_str
|
from common import draw_str
|
||||||
|
import getopt, sys
|
||||||
|
from itertools import count
|
||||||
|
|
||||||
|
help_message = '''
|
||||||
|
USAGE: turing.py [-o <output.avi>]
|
||||||
|
|
||||||
|
Press ESC to stop.
|
||||||
|
'''
|
||||||
|
print help_message
|
||||||
|
|
||||||
w, h = 512, 512
|
w, h = 512, 512
|
||||||
|
|
||||||
|
args, args_list = getopt.getopt(sys.argv[1:], 'o:', [])
|
||||||
|
args = dict(args)
|
||||||
|
out = None
|
||||||
|
if '-o' in args:
|
||||||
|
fn = args['-o']
|
||||||
|
out = cv2.VideoWriter(args['-o'], cv.CV_FOURCC(*'DIB '), 30.0, (w, h), False)
|
||||||
|
print 'writing %s ...' % fn
|
||||||
|
|
||||||
a = np.zeros((h, w), np.float32)
|
a = np.zeros((h, w), np.float32)
|
||||||
cv2.randu(a, np.array([0]), np.array([1]))
|
cv2.randu(a, np.array([0]), np.array([1]))
|
||||||
|
|
||||||
@ -19,12 +36,8 @@ def process_scale(a_lods, lod):
|
|||||||
v = cv2.GaussianBlur(d*d, (3, 3), 0)
|
v = cv2.GaussianBlur(d*d, (3, 3), 0)
|
||||||
return np.sign(d), v
|
return np.sign(d), v
|
||||||
|
|
||||||
print 'Generating AVI file. Press ESC to stop.'
|
|
||||||
out = cv2.VideoWriter('turing.avi', cv.CV_FOURCC(*'DIB '), 30.0, (w, h), False)
|
|
||||||
|
|
||||||
scale_num = 6
|
scale_num = 6
|
||||||
frame_num = 1000
|
for frame_i in count():
|
||||||
for frame_i in xrange(frame_num):
|
|
||||||
a_lods = [a]
|
a_lods = [a]
|
||||||
for i in xrange(scale_num):
|
for i in xrange(scale_num):
|
||||||
a_lods.append(cv2.pyrDown(a_lods[-1]))
|
a_lods.append(cv2.pyrDown(a_lods[-1]))
|
||||||
@ -37,12 +50,10 @@ for frame_i in xrange(frame_num):
|
|||||||
a += np.choose(mi, ms) * 0.025
|
a += np.choose(mi, ms) * 0.025
|
||||||
a = (a-a.min()) / a.ptp()
|
a = (a-a.min()) / a.ptp()
|
||||||
|
|
||||||
|
if out:
|
||||||
out.write(a)
|
out.write(a)
|
||||||
vis = a.copy()
|
vis = a.copy()
|
||||||
draw_str(vis, (20, 20), 'frame %d / %d' % (frame_i+1, frame_num))
|
draw_str(vis, (20, 20), 'frame %d' % frame_i)
|
||||||
cv2.imshow('a', vis)
|
cv2.imshow('a', vis)
|
||||||
if cv2.waitKey(5) == 27:
|
if cv2.waitKey(5) == 27:
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
print 'done'
|
|
||||||
cv2.waitKey()
|
|
Loading…
Reference in New Issue
Block a user