本文整理汇总了Python中SimpleCV.Display.writeFrame方法的典型用法代码示例。如果您正苦于以下问题:Python Display.writeFrame方法的具体用法?Python Display.writeFrame怎么用?Python Display.writeFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Display
的用法示例。
在下文中一共展示了Display.writeFrame方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import writeFrame [as 别名]
class Gui:
_layer_sets = { 'default': ['raw', 'robot0', 'robot1', 'robot2', 'robot3', 'ball'],
'squares1': ['squares', 'robot0', 'robot1', 'robot2', 'robot3', 'ball'],
'squares2': ['squares', 'robot0', 'robot1', 'robot2', 'robot3', 'ball'],
'squares3': ['squares', 'robot0', 'robot1', 'robot2', 'robot3', 'ball'],
'squares4': ['squares', 'robot0', 'robot1', 'robot2', 'robot3', 'ball'],
'ball': ['threshR', 'ball'] }
_layers = { 'raw': None,
'threshR': None,
'ball': None,
'robot0': None,
'robot1': None,
'robot2': None,
'robot3': None,
'squares': None }
_persistent_layers = { 'mouse': None }
def __init__(self, size=(720, 540)):
self._current_layer_set = self._layer_sets['default']
self._display = Display(size)
self._event_handler = Gui.EventHandler()
self._last_mouse_state = 0
self._show_mouse = True
self._last_frame = None
self._last_frame_time = time.time()
def __draw(self):
iterator = iter(self._current_layer_set)
base_layer = self._layers[iterator.next()]
if base_layer is None:
return
size = base_layer.size()
entity_layer = base_layer.dl()
for key in iterator:
to_draw = self._layers[key]
if isinstance(to_draw, DrawingLayer):
base_layer.addDrawingLayer(to_draw)
elif not to_draw is None:
to_draw.draw(entity_layer)
for layer in self._persistent_layers.itervalues():
if layer is not None:
base_layer.addDrawingLayer(layer)
final_image = base_layer.applyLayers()
self._display.writeFrame(final_image, fit=False)
def __update_fps(self):
this_frame_time = time.time()
this_frame = this_frame_time - self._last_frame_time
fps = 1.0 / this_frame
self._lastFrame = this_frame
self._last_frame_time = this_frame_time
layer = self._layers[self._current_layer_set[0]].dl()
layer.ezViewText('{0:.1f} fps'.format(fps), (10, 10))
def draw_crosshair(self, pos, layer_name = None):
size = self._layers['raw'].size()
if layer_name is not None:
layer = DrawingLayer(self._layers['raw'].size())
else:
layer = self._layers['raw'].dl()
layer.line((0, pos[1]), (size[0], pos[1]), color=(0, 0, 255))
layer.line((pos[0], 0), (pos[0], size[1]), color=(0, 0, 255))
if layer_name is not None:
self.update_layer(layer_name, layer)
def process_update(self):
"""Draw the image to the display, and process any events
"""
for event in pygame.event.get(pygame.KEYDOWN):
self._event_handler.process_key(chr(event.key % 0x100))
self._display.checkEvents()
mouseX = self._display.mouseX
mouseY = self._display.mouseY
if self._show_mouse:
self.draw_crosshair((mouseX, mouseY), 'mouse')
mouse_left = self._display.mouseLeft
# Only fire click event once for each click
if mouse_left == 1 and self._last_mouse_state == 0:
self._event_handler.process_click((mouseX, mouseY))
self._last_mouse_state = mouse_left
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import writeFrame [as 别名]
class Gui:
"""
Default layer groups available to display
First element is the 'base' layer, and must be an image,
the rest must be features and will be drawn on top
"""
layersets = {
'default': ['raw', 'yellow', 'blue', 'ball'],
'yellow': ['threshY', 'yellow'],
'blue': ['threshB', 'blue'],
'ball': ['threshR', 'ball']
}
def __init__(self, size=(720, 540)):
self._layers = {
# Base layers
'raw': None,
'threshY': None,
'threshB': None,
'threshR': None,
# Overlay layers
'yellow': None,
'blue': None,
'ball' : None,
}
# These layers are drawn regardless of the current layerset
self._persistentLayers = {
'mouse': None
}
self._currentLayerset = self.layersets['default']
self._display = Display(size)
self._eventHandler = Gui.EventHandler()
self._lastMouseState = 0
self._showMouse = True
self._lastFrame = None
self._lastFrameTime = time.time()
def __draw(self):
iterator = iter(self._currentLayerset)
# First element is the base layer
baseLayer = self._layers[iterator.next()]
if baseLayer is None:
return
size = baseLayer.size()
# Draw all entities to one layer (for speed)
entityLayer = baseLayer.dl()
for key in iterator:
toDraw = self._layers[key]
if toDraw is None:
continue
elif isinstance(toDraw, DrawingLayer):
baseLayer.addDrawingLayer(toDraw)
else:
toDraw.draw(entityLayer)
for layer in self._persistentLayers.itervalues():
if layer is not None:
baseLayer.addDrawingLayer(layer)
finalImage = baseLayer.applyLayers()
self._display.writeFrame(finalImage, fit=False)
def __updateFps(self):
smoothConst = 0.1
thisFrameTime = time.time()
thisFrame = thisFrameTime - self._lastFrameTime
if self._lastFrame is not None:
# Smooth values
thisFrame = thisFrame * (1 - smoothConst) + smoothConst * self._lastFrame
fps = 1.0 / thisFrame
self._lastFrame = thisFrame
self._lastFrameTime = thisFrameTime
layer = self._layers['raw'].dl()
layer.ezViewText('{0:.1f} fps'.format(fps), (10, 10))
def drawCrosshair(self, pos, layerName = None):
size = self._layers['raw'].size()
if layerName is not None:
layer = self.getDrawingLayer()
else:
layer = self._layers['raw'].dl()
layer.line((0, pos[1]), (size[0], pos[1]), color=(0, 0, 255))
layer.line((pos[0], 0), (pos[0], size[1]), color=(0, 0, 255))
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import writeFrame [as 别名]
class Gui:
"""
Default layer groups available to display
First element is the 'base' layer, and must be an image,
the rest must be features and will be drawn on top
"""
layersets = {
'default': ['raw', 'yellow', 'blue', 'ball'],
'yellow': ['threshY', 'yellow'],
'blue': ['threshB', 'blue'],
'ball': ['threshR', 'ball']
}
h_min = s_min = v_min = 255
h_max = s_max = v_max = 0
# Show pixel mode: turn on/off by 'p', show the HSV of the pixel at the mouse
showPixel = False
# Record pixel mode: use the current pixel to update threshold
recordPixel = False
def __init__(self, noGui):
self._layers = {
# Base layers
'raw': None,
'threshY': None,
'threshB': None,
'threshR': None,
# Overlay layers
'yellow': None,
'blue': None,
'ball': None,
}
# These layers are drawn regardless of the current layerset
self._persistentLayers = {
'mouse': None
}
self._currentLayerset = self.layersets['default']
self._display = Display()
self._eventHandler = Gui.EventHandler()
self._lastMouseState = 0
self._showMouse = True
self._lastFrame = None
self._lastFrameTime = time.time()
def __draw(self):
iterator = iter(self._currentLayerset)
# First element is the base layer
baseLayer = self._layers[iterator.next()]
if baseLayer is None:
return
# Draw all entities to one layer (for speed)
entityLayer = baseLayer.dl()
for key in iterator:
toDraw = self._layers[key]
if toDraw is None:
continue
elif isinstance(toDraw, DrawingLayer):
baseLayer.addDrawingLayer(toDraw)
else:
toDraw.draw(entityLayer)
for layer in self._persistentLayers.itervalues():
if layer is not None:
baseLayer.addDrawingLayer(layer)
finalImage = baseLayer.applyLayers()
self._display.writeFrame(finalImage, fit=False)
def __updateFps(self):
smoothConst = 0.1
thisFrameTime = time.time()
thisFrame = thisFrameTime - self._lastFrameTime
if self._lastFrame is not None:
# Smooth values
thisFrame = thisFrame * (1 - smoothConst) + smoothConst * self._lastFrame
self._lastFrame = thisFrame
self._lastFrameTime = thisFrameTime
def drawCrosshair(self, pos, layerName=None):
size = self._layers['raw'].size()
if layerName is not None:
layer = self.getDrawingLayer()
else:
layer = self._layers['raw'].dl()
layer.line((0, pos[1]), (size[0], pos[1]), color=(0, 0, 255))
layer.line((pos[0], 0), (pos[0], size[1]), color=(0, 0, 255))
if layerName is not None:
self.updateLayer(layerName, layer)
#.........这里部分代码省略.........