Ejemplo n.º 1
0
class Cameo(object):
    def __init__(self):
        self._windowManager = WindowManager('Cameo', self.onKeyPress)
        self._captureManager = CaptureManager(cv2.VideoCapture(0),
                                              self._windowManager, 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
            # TODO: Filter the frame (Chapter 3).
            filters.strokeEdges(frame, frame)
            self._curveFilter.apply(frame, frame)

            self._captureManager.exitFrame()
            self._windowManager.processEvents()

    def onKeyPress(self, keycode):
        """Handle a keycode/
        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()
Ejemplo n.º 2
0
class Cameo(object):
    def __init__(self):

        self._windowManager = WindowManager('Cameo', self.onkeypress)

        self._captureManager = CaptureManager(cv2.VideoCapture(0),
                                              self._windowManager, True)

    # self._curveFilter=filters.BGRPortraCurveFilter()

    def run(self):

        self._windowManager.createWindow()

        while self._windowManager.isWindowCreated:
            self._captureManager.enterFrame()

            frame = self._captureManager.frame

            # filters.strokeEdges(frame,frame)

            # self._curveFilter.apply(frame,frame)

            self._captureManager.exitFrame()

            self._windowManager.processEvents()

    def onkeypress(self, keycode):
        '''

            space-> 载图

            tab->启动和停止视频录制

            esc->退出应用



        :param keycode:

        :return:

        '''

        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:  # esc

            self._windowManager.destroyWindow()