本文整理汇总了Python中managers.WindowManager.processEvents方法的典型用法代码示例。如果您正苦于以下问题:Python WindowManager.processEvents方法的具体用法?Python WindowManager.processEvents怎么用?Python WindowManager.processEvents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类managers.WindowManager
的用法示例。
在下文中一共展示了WindowManager.processEvents方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CameoDepth
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class CameoDepth(Cameo):
def __init__(self):
self._windowManager = WindowManager('Cameo',
self.onKeypress)
self._captureManager = CaptureManager(
cv2.VideoCapture(0), self._windowManager, True)
self._faceTracker = FaceTracker()
self._shouldDrawDebugRects = False
self._curveFilter = filters.BGRPortraCurveFilter()
def run(self):
"""Run the main loop."""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
self._faceTracker.update(frame)
faces = self._faceTracker.faces
rects.swapRects(frame, frame,
[face.faceRect for face in faces])
filters.strokeEdges(frame, frame)
self._curveFilter.apply(frame, frame)
if self._shouldDrawDebugRects:
self._faceTracker.drawDebugRects(frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
示例2: Cameo
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(0), self._windowManager, True)
# self._curveFilter = filters.EmbossFilter()
def run(self):
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
filters.strokeEdge(frame, frame)
# self._curveFilter.apply(frame, frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
def onKeypress(self, keycode):
if keycode == 32: #space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: #tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
else:
self._captureManager.stopWritingVideo()
if keycode ==27:#esc
self._windowManager.destroyWindow()
示例3: Cameo
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo',
self.onKeypress)
self._captureManager = CaptureManager(
cv2.VideoCapture(0), self._windowManager, True)
def run(self):
"""Run the main loop."""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
# TODO: Filter the frame (Chapter 3).
self._captureManager.exitFrame()
self._windowManager.processEvents()
def onKeypress (self, keycode):
"""Handle a keypress.
space -> Take a screenshot.
tab -> Start/stop recording a screencast.
escape -> Quit.
"""
if keycode == 32: # space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: # tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 27: # escape
self._windowManager.destroyWindow()
示例4: Cameo
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo',
self.onKeypress)
self._captureManager = CaptureManager(
cv2.VideoCapture(0), self._windowManager, True)
self._faceTracker = FaceTracker()
self._shouldDrawDebugRects = False
self._curveFilter = filters.BGRPortraCurveFilter()
def run(self):
"""Run the main loop."""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
self._faceTracker.update(frame)
faces = self._faceTracker.faces
rects.swapRects(frame, frame,
[face.faceRect for face in faces])
filters.strokeEdges(frame, frame)
self._curveFilter.apply(frame, frame)
if self._shouldDrawDebugRects:
self._faceTracker.drawDebugRects(frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
def onKeypress(self, keycode):
"""Handle a keypress.
space -> Take a screenshot.
tab -> Start/stop recording a screencast.
x -> Start/stop drawing debug rectangles around faces.
escape -> Quit.
"""
if keycode == 32: # space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: # tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo(
'screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 120: # x
self._shouldDrawDebugRects = \
not self._shouldDrawDebugRects
elif keycode == 27: # escape
self._windowManager.destroyWindow()
示例5: Tracker
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
#.........这里部分代码省略.........
def run( self ):
# Show windows
self._rawWindow.createWindow()
self._overlayWindow.createWindow()
while self._rawWindow.isWindowCreated:
self._cap.enterFrame()
frame = self._cap.frame
# Probably not useful, removes errors when playing from video
# if not self._captureManager.gotFrame:
# self.shutDown()
# break
# Display raw frame to rawWindow
t1 = time.time()
# Get frame
frame = self._cap.frame
# Show frame to raw feed
self._rawWindow.show(frame)
# If tracking is enabled or motors are on, start tracking
if time.time() - self._lastCheck >= self._sampleFreq:
if self.finderArgs['method'] in ['lazyc', 'lazyd']:
self.gaussian = self._wormFinder.processFrame( frame )
self.overlayImage = copy.deepcopy(frame)
if self.motorsOn:
self._wormFinder.decideMove()
self._lastCheck = time.time()
self._wormFinder.drawDebugCropped( self.overlayImage)
self._wormFinder.drawTextStatus(self.overlayImage,self._cap.isWritingVideo, self.motorsOn)
self._overlayWindow.show(self.overlayImage)
if self.finderArgs['method'] in ['test','conf']:
self._wormFinder.drawTest( frame )
self._cap.exitFrame()
self._rawWindow.processEvents()
logt.debug('frame processing took: %0.6f' % (time.time() - t1))
@property
def isDebug( self ):
return logt.getEffectiveLevel() <= logging.INFO
def shutDown( self ):
self._rawWindow.destroyWindow()
#if not self.isDebug:
if self._cap.isWritingVideo:
self._cap.stopWritingVideo()
try:
# self._wormFinder.writeOut('%s-%s' % (self.finderArgs['method'], self.captureSource))
self._wormFinder.servos.disableMotors()
self._wormFinder.servos.closeSerial()
except Exception as e:
logt.exception(str(e))
def onKeypress ( self, keycode ):
'''
Keypress options
<SPACE> --- Motors On
< TAB > --- start/stop recording screencast
< ESC > --- quit
'''
if keycode == 32: #space
if self.motorsOn:
self.motorsOn = False#_captureManager.writeImage('screenshot.png')
if not self.isDebug:
self._wormFinder.servos.disableMotors()
#cv2.displayOverlay('Overlay','Motors disabled', 0)
else:
self.motorsOn = True
self._wormFinder.launch = 0
if not self.isDebug:
self._wormFinder.servos.enableMotors()
self._wormFinder.launch = 0
time.sleep(2)
#cv2.displayOverlay('Overlay','Motors enabled', 0)
elif keycode == 9: #tab
if not self._cap.isWritingVideo:
self._cap.startWritingVideo(
'worm%s.avi' % time.strftime("%Y_%m_%d-%H-%M-%S", time.localtime(time.time())),
cv2.cv.CV_FOURCC(*'MJPG'))
# cv2.displayOverlay('Overlay','Writing Video', 0)
else:
self._cap.stopWritingVideo()
# cv2.displayOverlay('Overlay','Not writing Video', 0)
elif keycode == 27: #escape
self.shutDown()
示例6: BenFinder
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
#.........这里部分代码省略.........
frame = cv2.multiply(frame,benMask,dst=frame,dtype=-1)
bri = filters.getMean(frame,benMask)
#print "%4.0f, %3.0f" % (bri[0],self._captureManager.fps)
self._ts.addSamp(bri[0])
if (self._frameCount < 15):
self._frameCount = self._frameCount +1
else:
self._ts.plotRawData()
self._ts.findPeaks()
self._frameCount = 0
else:
print "Auto background subtract only works for depth images!"
else:
if (self._captureManager.channel == \
depth.CV_CAP_OPENNI_DEPTH_MAP):
cv2.absdiff(frame,self.background_depth_img,frame)
benMask = filters.getBenMask(frame,8)
bri = filters.getMean(frame,benMask)
print bri
elif (self._captureManager.channel == \
depth.CV_CAP_OPENNI_BGR_IMAGE):
cv2.absdiff(frame,self.background_video_img,frame)
else:
print "Error - Invalid Channel %d." % \
self._captureManager.channel
#ret,frame = cv2.threshold(frame,200,255,cv2.THRESH_TOZERO)
#self._faceTracker.update(frame)
#faces = self._faceTracker.faces
#if self._shouldDrawDebugRects:
# self._faceTracker.drawDebugRects(frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
def onKeypress(self, keycode):
"""Handle a keypress.
space -> Take a screenshot.
tab -> Start/stop recording a screencast.
x -> Start/stop drawing debug rectangles around faces.
a -> toggle automatic accumulated background subtraction on or off.
b -> toggle simple background subtraction on or off.
s -> Save current frame as background image.
d -> Toggle between video and depth map view
i -> Display the background image that is being used for subtraction.
escape -> Quit.
"""
print "keycode=%d" % keycode
if keycode == 32: # space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: # tab
if not self._captureManager.isWritingVideo:
print "Starting Video Recording..."
self._captureManager.startWritingVideo(
'screencast.avi')
else:
print "Stopping video recording"
self._captureManager.stopWritingVideo()
elif keycode == 120: # x
self._shouldDrawDebugRects = \
not self._shouldDrawDebugRects
elif (chr(keycode)=='a'): # Autometic background subtraction
if (self._autoBackgroundSubtract == True):
print "Switching off auto background Subtraction"
示例7: Facedetect
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Facedetect(object):
def __init__(self):
self._windowManager = WindowManager('Facedetect', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(camera_nr), self._windowManager, True)
self._faceTracker = FaceTracker()
self._shouldDrawDebugRects = True
self._curveFilter = filters.BGRPortraCurveFilter()
def run(self):
"""Run the main loop."""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
t = cv2.getTickCount()
self._faceTracker.update(frame)
faces = self._faceTracker.faces
t = cv2.getTickCount() - t
print("time taken for detection = %gms" % (t/(cv2.getTickFrequency())*1000.))
# uncomment this line for swapping faces
#rects.swapRects(frame, frame, [face.faceRect for face in faces])
#filters.strokeEdges(frame, frame)
#self._curveFilter.apply(frame, frame)
if self._shouldDrawDebugRects:
self._faceTracker.drawDebugRects(frame)
self._faceTracker.drawLinesFromCenter(frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
def onKeypress(self, keycode):
"""Handle a keypress.
space -> Take a screenshot.
tab -> Start/stop recording a screencast.
x -> Start/stop drawing debug rectangles around faces.
escape -> Quit.
"""
if keycode == 32: # space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: # tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo(
'screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 120: # x
self._shouldDrawDebugRects = \
not self._shouldDrawDebugRects
elif keycode == 27: # escape
self._windowManager.destroyWindow()
# When everything is done, release the capture
self._captureManager.release()
示例8: Tracker
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
#.........这里部分代码省略.........
self._rawWindow.createWindow()
self._overlayWindow.createWindow()
i = 0
while self._rawWindow.isWindowCreated:
self._cap.enterFrame()
frame = self._cap.frame
# Probably not useful, removes errors when playing from video
# if not self._captureManager.gotFrame:
# self.shutDown()
# break
# Display raw frame to rawWindow
t1 = time.time()
# Get frame
frame = self._cap.frame
# Show frame to raw feed
self._rawWindow.show(frame)
# If tracking is enabled or motors are on, start tracking
if time.time() - self._lastCheck >= self._sampleFreq:
if self.finderArgs["method"] in ["lazyc", "lazyd", "lazy"]:
self.gaussian = self._wormFinder.processFrame(frame)
self.overlayImage = copy.deepcopy(frame)
if self.motorsOn:
self._wormFinder.decideMove()
self._lastCheck = time.time()
self._wormFinder.drawDebugCropped(self.overlayImage)
self._wormFinder.drawTextStatus(self.overlayImage, self._cap.isWritingVideo, self.motorsOn)
self._overlayWindow.show(self.overlayImage)
# if self.gaussian is not None:
# self._gaussianWindow.show(self.gaussian)
# cv2.imwrite('g-%d.jpg' % i, self.gaussian )
# cv2.imwrite('o-%d.jpg' % i, self.overlayImage )
if self.finderArgs["method"] in ["test", "conf"]:
# self.overlayImage = copy.deepcopy(frame)
self._wormFinder.drawTest(frame) # self.overlayImage)
# self._overlayWindow.show(self.overlayImage)
i += 1
self._cap.exitFrame()
self._rawWindow.processEvents()
logt.info("processing: %0.6f" % (time.time() - t1))
@property
def isDebug(self):
return logt.getEffectiveLevel() <= logging.INFO
def shutDown(self):
self._rawWindow.destroyWindow()
if self._cap.isWritingVideo:
self._cap.stopWritingVideo()
try:
self._wormFinder.servos.disableMotors()
self._wormFinder.servos.closeSerial()
except Exception as e:
logt.exception(str(e))
def onKeypress(self, keycode):
"""
Keypress options
<SPACE> --- Motors On
< TAB > --- start/stop recording screencast
< ESC > --- quit
"""
if keycode == 32: # space
if self.motorsOn:
self.motorsOn = False # _captureManager.writeImage('screenshot.png')
if not self.isDebug:
self._wormFinder.servos.disableMotors()
else:
self.motorsOn = True
self._wormFinder.launch = 0
if not self.isDebug:
self._wormFinder.servos.enableMotors()
self._wormFinder.launch = 0
time.sleep(2)
elif keycode == 9: # tab
if not self._cap.isWritingVideo:
self._cap.startWritingVideo(
"worm%s.avi" % time.strftime("%Y_%m_%d-%H-%M-%S", time.localtime(time.time())),
cv2.cv.CV_FOURCC(*"MJPG"),
)
else:
self._cap.stopWritingVideo()
elif keycode == 27: # escape
self.shutDown()
示例9: Browser
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Browser(object):
def __init__(self,video_source):
self._windowManager = WindowManager('Browser', self.onKeypress)
self._captureManager = CaptureManager(video_source, self._windowManager, True)
self._faceTracker = FaceTracker()
self._shouldDrawDebugRects = False
self._curveFilter = filters.BGRPortraCurveFilter()
def run(self):
"""Run the main loop."""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
if frame is not None:
print "got frame"
self._faceTracker.update(frame)
faces = self._faceTracker.faces
rects.swapRects(frame, frame,
[face.faceRect for face in faces])
#filters.strokeEdges(frame, frame)
#self._curveFilter.apply(frame, frame)
if self._shouldDrawDebugRects:
self._faceTracker.drawDebugRects(frame)
else:
print "got None frame"
print "press any key to exit."
cv2.waitKey(0)
break
self._captureManager.exitFrame()
waitkey_time=1
if self._captureManager._video_source!=0:
waitkey_time=500
self._windowManager.processEvents(waitkey_time)
def onKeypress(self, keycode):
"""Handle a keypress.
space -> Take a screenshot.
tab -> Start/stop recording a screencast.
x -> Start/stop drawing debug rectangles around faces.
escape -> Quit.
"""
if keycode == 32: # space
self._captureManager.writeImage('screenshot.png')
elif keycode == 9: # tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo(
'/Users/xcbfreedom/Documents/screencast.avi')
else:
self._captureManager.stopWritingVideo()
elif keycode == 120: # x
self._shouldDrawDebugRects = \
not self._shouldDrawDebugRects
elif keycode == 27: # escape
self._windowManager.destroyWindow()
示例10: Cameo
# 需要导入模块: from managers import WindowManager [as 别名]
# 或者: from managers.WindowManager import processEvents [as 别名]
class Cameo(object):
def __init__(self):
self._windowManager = WindowManager('Cameo', self.onKeypress)
self._captureManager = CaptureManager(cv2.VideoCapture(0),
self._windowManager, True)
self._curveFilter = filters.BGRProviaCurveFilter()
self._faceTracker = FaceTracker()
self._shouldDrawDebugRects = False
def run(self):
""" Run the main loop """
self._windowManager.createWindow()
print("Window '{}' Created".format(self._windowManager.windowName))
print("\n{}\n{}\n{}\n{}".format("Controls:",
"space --> Take a screenshot",
"tab --> Start/stop recording a screencast",
"escape --> Quit"))
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
self._faceTracker.update(frame)
faces = self._faceTracker.faces
rects.swapRects(frame, frame, [face.faceRect for face in faces])
# Add filtering to the frame
filters.strokeEdges(frame,frame)
self._curveFilter.apply(frame,frame)
if self._shouldDrawDebugRects:
self._faceTracker.drawDebugRects(frame)
self._captureManager.exitFrame()
self._windowManager.processEvents()
def stop(self):
print("[CAMEO] closing all processes")
self._captureManager._capture.release()
self._windowManager.destroyWindow()
def onKeypress(self, keycode):
""" Handle a keypress
space --> Take a screenshot
tab --> Start/stop recording a screencast
x --> Toggle drawing debug rectangles around faces
escape --> Quit
"""
if keycode == 32: # Space
self._captureManager.writeImage('screenshot.png');
print("Writing image to file....")
elif keycode == 9: # Tab
if not self._captureManager.isWritingVideo:
self._captureManager.startWritingVideo('screencast.avi')
print("Writing video to file...")
else:
self._captureManager.stopWritingVideo()
print("Stopped writing video")
elif keycode == 120: # x
self._shouldDrawDebugRects = not self._shouldDrawDebugRects
print("Toggled drawing rectangles")
elif keycode == 27: # escape
print("Closing Window...")
self._windowManager.destroyWindow()