当前位置: 首页>>代码示例>>Python>>正文


Python CaptureManager.release方法代码示例

本文整理汇总了Python中managers.CaptureManager.release方法的典型用法代码示例。如果您正苦于以下问题:Python CaptureManager.release方法的具体用法?Python CaptureManager.release怎么用?Python CaptureManager.release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在managers.CaptureManager的用法示例。


在下文中一共展示了CaptureManager.release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Facedetect

# 需要导入模块: from managers import CaptureManager [as 别名]
# 或者: from managers.CaptureManager import release [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()
开发者ID:StefQM,项目名称:facedetect,代码行数:63,代码来源:facedetect.py


注:本文中的managers.CaptureManager.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。