@@ -0,0 +1,1305 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A# take_face_pictures.py%0A# author: Kentaro Wada %3Cwww.kentaro.wada@gmail.com%3E%0A%0Aimport cv2%0A%0A%0Aclass TakeFacePictures(object):%0A    def __init__(self):%0A        %22%22%22Initialize camera%22%22%22%0A        self.cap = cv2.VideoCapture(0)%0A        self.end_flag = False%0A        self.frame = None%0A%0A    def capture_loop(self, mirror=True, size=None):%0A        %22%22%22Capturing camera loop%22%22%22%0A        while True:%0A            # Capture frame-by-frame%0A            ret, self.frame = self.cap.read()%0A            # Act like mirror or not%0A            if mirror is True:%0A                self.frame = self.frame%5B:,::-1%5D%0A            # Resize frame%0A            if size is not None and len(size) == 2:%0A                self.frame = cv2.resize(self.frame, size)%0A            # Display the resulting frame%0A            cv2.imshow('camera capture', self.frame)%0A            # Key event%0A            self._key_event(cv2.waitKey(1))%0A            # end flag%0A            if self.end_flag is True:%0A                break%0A%0A    def _key_event(self, k):%0A        if k == 27:%0A            self.end_flag = True%0A        elif k == ord('s'):%0A            cv2.imwrite('capture.png', self.frame)%0A%0A    def __del__(self):%0A        %22%22%22When everything done, release the capture%22%22%22%0A        cap.release()%0A        cv2.destroyAllWindows()

add take_face_pictures.py