本文整理汇总了Python中SimpleCV.Display.checkEvents方法的典型用法代码示例。如果您正苦于以下问题:Python Display.checkEvents方法的具体用法?Python Display.checkEvents怎么用?Python Display.checkEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleCV.Display
的用法示例。
在下文中一共展示了Display.checkEvents方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import checkEvents [as 别名]
#.........这里部分代码省略.........
# 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))
if layerName is not None:
self.updateLayer(layerName, layer)
def loop(self):
"""
Draw the image to the display, and process any events
"""
for event in pygame.event.get(pygame.KEYDOWN):
self._eventHandler.processKey(chr(event.key % 0x100))
self._display.checkEvents()
mouseX = self._display.mouseX
mouseY = self._display.mouseY
if self._showMouse:
self.drawCrosshair((mouseX, mouseY), 'mouse')
mouseLeft = self._display.mouseLeft
# Only fire click event once for each click
if mouseLeft == 1 and self._lastMouseState == 0:
self._eventHandler.processClick((mouseX, mouseY))
self._lastMouseState = mouseLeft
# Processing OpenCV events requires calling cv.WaitKey() with a reasonable timeout,
# which hits our framerate hard (NOTE: Need to confirm this on DICE), so only do
# this if the focus isn't on the pygame (image) window`
if not pygame.key.get_focused():
c = cv.WaitKey(2)
self._eventHandler.processKey(chr(c % 0x100))
self.__updateFps()
self.__draw()
def getEventHandler(self):
return self._eventHandler
def getDrawingLayer(self):
return DrawingLayer(self._layers['raw'].size())
def updateLayer(self, name, layer):
"""
Update the layer specified by 'name'
示例2: turk
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import checkEvents [as 别名]
def turk(self,saveOriginal=False,disp_size=(800,600),showKeys=True,font_size=16,color=Color.RED,spacing=10 ):
"""
**SUMMARY**
This function does the turning of the data. The method goes through each image,
applies the preprocessing (which can return multiple images), displays each image
with an optional display of the key mapping. The user than selects the key that describes
the class of the image. The image is then post processed and saved to the directory.
The escape key kills the turking, the space key skips an image.
**PARAMETERS**
* *saveOriginal* - if true save the original image versus the preprocessed image.
* *disp_size* - size of the display to create.
* *showKeys* - Show the key mapping for the turking. Note that on small images this may not render correctly.
* *font_size* - the font size for the turking display.
* *color* - the font color.
* *spacing* - the spacing between each line of text on the display.
**RETURNS**
Nothing but stores each image in the directory. The image sets are also available
via the getClass method.
**EXAMPLE**
>>>> def GetBlobs(img):
>>>> blobs = img.findBlobs()
>>>> return [b.mMask for b in blobs]
>>>> def ScaleIng(img):
>>>> return img.resize(100,100).invert()
>>>> turker = TurkingModule(['./data/'],['./turked/'],['apple','banana','cherry'],['a','b','c'],preProcess=GetBlobs,postProcess=ScaleInv]
>>>> turker.turk()
>>>> # ~~~ stuff ~~~
>>>> turker.save('./derp.pkl')
** TODO **
TODO: fix the display so that it renders correctly no matter what the image size.
TODO: Make it so you can stop and start turking at any given spot in the process
"""
disp = Display(disp_size)
bail = False
for img in self.srcImgs:
print img.filename
samples = self.preProcess(img)
for sample in samples:
if( showKeys ):
sample = self._drawControls(sample,font_size,color,spacing )
sample.save(disp)
gotKey = False
while( not gotKey ):
keys = disp.checkEvents(True)
for k in keys:
if k in self.keyMap:
if saveOriginal:
self._saveIt(img,self.keyMap[k])
else:
self._saveIt(sample,self.keyMap[k])
gotKey = True
if k == 'space':
gotKey = True # skip
if k == 'escape':
return
示例3: Camera
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import checkEvents [as 别名]
cam = Camera()
path = "./data/"
ext = ".png"
suit_ptr = 0
rank_ptr = 0
current_dir = ""
allDone = False
for s in SUITS:
for r in RANKS:
directory = path+s+"/"+r+"/"
if not os.path.exists(directory):
os.makedirs(directory)
print "Current Data: " + str(RANKS[rank_ptr])+str(SUITS[suit_ptr])
while not allDone :
keys = disp.checkEvents()
img = cam.getImage()
for k in keys:
if( k == pg.K_SPACE ):
directory = path+SUITS[suit_ptr]+"/"+RANKS[rank_ptr]+"/"
files = glob.glob(directory+"*.*")
count = len(files)
fname = directory+RANKS[rank_ptr]+SUITS[suit_ptr]+"-"+str(count)+ext
img.save(fname)
print "Saved: " + fname
if( k == pg.K_n ):
if rank_ptr == len(RANKS)-1 and suit_ptr == len(SUITS)-1:
allDone = True
elif rank_ptr == len(RANKS)-1:
rank_ptr = 0
suit_ptr = suit_ptr + 1
示例4: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import checkEvents [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
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import checkEvents [as 别名]
#.........这里部分代码省略.........
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)
def loop(self):
"""
Draw the image to the display, and process any events
"""
for event in pygame.event.get(pygame.KEYDOWN):
self._eventHandler.processKey(chr(event.key % 0x100))
self._display.checkEvents()
mouseX = self._display.mouseX
mouseY = self._display.mouseY
if self._showMouse:
self.drawCrosshair((mouseX, mouseY), 'mouse')
mouseLeft = self._display.mouseLeft
# Only fire click event once for each click
if mouseLeft == 1 and self._lastMouseState == 0:
self._eventHandler.processClick((mouseX, mouseY))
self._lastMouseState = mouseLeft
# Processing OpenCV events requires calling cv.WaitKey() with a reasonable timeout,
# which hits our framerate hard (NOTE: Need to confirm this on DICE), so only do
# this if the focus isn't on the pygame (image) window`
if not pygame.key.get_focused():
c = cv.WaitKey(2)
self._eventHandler.processKey(chr(c % 0x100))
if self.showPixel:
self.__updatePixel()
self.__updateFps()
self.__draw()
def getEventHandler(self):
return self._eventHandler
def getDrawingLayer(self):
return DrawingLayer(self._layers['raw'].size())
def updateLayer(self, name, layer):