本文整理汇总了Python中writer.Writer.update方法的典型用法代码示例。如果您正苦于以下问题:Python Writer.update方法的具体用法?Python Writer.update怎么用?Python Writer.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类writer.Writer
的用法示例。
在下文中一共展示了Writer.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: App
# 需要导入模块: from writer import Writer [as 别名]
# 或者: from writer.Writer import update [as 别名]
class App(object):
"""Manage application controllers, respond to user input, run master loop.
This class wraps together the various components of the application. It is
the application entry point. On startup, it creates an instance of each
controller. The run() method starts each controller and runs the master loop
until the user quits.
Settings:
experimentName: used to label the output directory and in output metadata
keyBindings: a dictionary where the keys are 'quit', 'toggleStimulator',
and 'triggerStimulator', and the values are one-character strings
representing the button that triggers the action specified by the key
outputRootDir: directory where the folder containing trial data will be
created
"""
def __init__(self, **kwargs):
"""Initialize the keycode bindings and all controllers, create output dir."""
settings = {
'experimentName' : 'someNameHere',
'outputRootDir' : os.path.normpath(os.path.expanduser("~/kauferdata")),
'keyBindings' : {
'quit' : 'q',
'toggleStimulator' : 't',
'triggerStimulator' : 's'
},
'audio' : {},
'gui' : {},
'stimulator' : { 'activeProtocolName' : 'nucleusAccumbensExample' },
'tracker' : {},
'videoIn' : {},
'videoOut' : {},
'writer' : {},
}
settings.update(kwargs)
trialDir = "{0}_{1}_{2}".format(time.strftime("%y%m%d%H%M%S"),
settings['experimentName'], settings['stimulator']['activeProtocolName'])
settings['outputDataDir'] = os.path.join(settings['outputRootDir'], trialDir)
self.keyBindings = settings['keyBindings']
self.keycodeBindings = {k: getattr(opencvgui.keycodes, v)
for k,v in self.keyBindings.items() }
os.makedirs(os.path.join(settings['outputDataDir'], 'audio'))
self.writeExperimentData(settings)
for x in ['audio', 'videoOut', 'writer']:
kwargs[x] = {} if not kwargs.has_key(x) else kwargs[x]
kwargs[x]['outputDataDir'] = settings['outputDataDir']
# gui and writer both need a reference to the app instance because they
# draw on the state of so many other controllers
self.audio = Audio(**settings['audio'])
self.gui = Gui(self, **settings['gui'])
self.stimulator = Stimulator(**settings['stimulator'])
self.tracker = Tracker(**settings['tracker'])
self.videoIn = VideoIn(**settings['videoIn'])
self.videoOut = VideoOut(**settings['videoOut'])
self.writer = Writer(self, **settings['writer'])
def run(self):
"""Respond to user input and run the master application loop.
This method has three basic sections. Before the loop starts, the start()
method is called on all controllers. The central loop calls update() on
each controller until it is terminated by a user-issued quit keystroke.
Keystrokes are listened for at the start of each loop iteration.
"""
self.printKeybindings()
self.startTime = self.lastTime = time.clock()
self.audio.start()
self.gui.start()
self.stimulator.start()
self.tracker.start()
self.videoIn.start()
self.videoOut.start()
self.writer.start()
while True:
# respond to user input
lastKeyStroke = cv2.waitKey(20) # 20 is the number of ms to wait for key
if lastKeyStroke != -1: # -1 means there was no keystroke
if lastKeyStroke == self.keycodeBindings['quit']:
break
if lastKeyStroke == self.keycodeBindings['triggerStimulator']:
self.stimulator.trigger()
if lastKeyStroke == self.keycodeBindings['toggleStimulator']:
self.stimulator.toggle()
# update state
self.currTime = time.clock()
self.totalTimeElapsed = self.currTime - self.startTime
self.audio.update()
self.videoIn.update()
self.tracker.update(self.videoIn, self.currTime)
self.stimulator.update(self.currTime, self.tracker)
self.videoOut.update(self.videoIn, self.tracker, self.stimulator)
self.gui.update()
self.lastTime = self.currTime
self.writer.update()
#.........这里部分代码省略.........