예제 #1
0
class Application:
    def __init__(self, **kwargs):
        self.verbose = kwargs.get('verbose', DEFAULT_VERBOSE)
        self.webcam = Webcam(**kwargs)
        self.gpio = GPIO(inputs = INPUT_PINS, outputs = OUTPUT_PINS)
            
        
    def main_loop(self):
        i = 0
        try:
            self.gpio.export()
            while True:
                button_state = self.gpio[SNAP_BUTTON_PIN]
                self.gpio[SNAP_LED_PIN] = button_state
                if button_state:
                    dt = datetime.datetime.now()
                    filename_prefix = dt.strftime("%Y-%m-%d_%H_%M_%S")
                    filename_suffix = "_img%03d" % i
                    self.webcam.take_photo(filename_prefix = filename_prefix,
                                           filename_suffix = filename_suffix,
                                           blocking = True,
                                           )
                    self.gpio[SNAP_LED_PIN] = button_state
                time.sleep(SLEEP_TIME)
        except KeyboardInterrupt:
            if self.verbose:
                print "user aborted capture...goodbye"
        finally:
            self.gpio.unexport()
예제 #2
0
파일: utils.py 프로젝트: Synez7/TER_S6
def emotion_recognition():
    client = docker.from_env()
    t = time.time()

    isOpen = Webcam.open()
    if not isOpen:
        print("ERROR: cannot open webcam")
        return None

    Webcam.take_photo(path_volume + "face.jpg")
    Webcam.close()

    if not watch(path_volume + "face.jpg", t):
        print("ERROR: cannot take photo")
        return None

    t = time.time()
    client.containers.run('app_emotion_recognition',
                          command='volume/face.jpg volume/emotion.txt',
                          volumes=volumes,
                          auto_remove=True)

    os.remove(path_volume + "face.jpg")

    if not watch(path_volume + "emotion.txt", t):
        print("ERROR: emotion_recognition cannot detect face or emotion")
        return None

    f = open(path_volume + "emotion.txt", "r")
    res = f.readline()
    f.close()
    if not res.isdigit():
        print("ERROR: emotion is not int")
        return None

    os.remove(path_volume + "emotion.txt")

    emotion_index = int(res)

    if emotion_index < 0:
        return None
    else:
        return EMOTIONS[emotion_index]
예제 #3
0
파일: utils.py 프로젝트: Synez7/TER_S6
def face_recognizer(face_path=None, face_bib="faces.json"):

    if not face_path:
        face_path = "face.jpg"
        t = time.time()

        isOpen = Webcam.open()
        if not isOpen:
            print("ERROR: cannot open webcam")
            return None

        Webcam.take_photo(path_volume + face_path)
        Webcam.close()

        if not watch(path_volume + face_path, t):
            print("ERROR: cannot take photo")
            return None

    client = docker.from_env()

    t = time.time()
    face_path = "face.jpg"

    client.containers.run('app_face_recognizer',
                          command='volume/' + face_path + ' volume/' +
                          face_bib + ' volume/face_reco.txt volume',
                          volumes=volumes,
                          auto_remove=True)
    os.remove(path_volume + face_path)

    if not watch(path_volume + "face_reco.txt", t):
        print("ERROR: face_recognizer cannot detect any face")
        return None

    f = open(path_volume + "face_reco.txt", "r")
    name = f.readline()
    f.close()

    os.remove(path_volume + "face_reco.txt")

    return name