def locate(self, image): face = None try: face = self._face_detector.detect(image) LOGGER.debug(_("Found the face")) except FeatureNotFoundException: return True try: left_eye = self._left_eye_detector.detect(face["image"]) LOGGER.debug(_("Found the left eye at %s"), left_eye) except FeatureNotFoundException: return True try: open_eye = self._open_eye_detector.detect(face["image"]) LOGGER.debug(_("Found an open eye at %s"), open_eye) return True except FeatureNotFoundException: return False
def set_position(self, position=None): '''Move pointer to position (x, y). If position is None, no change is made.''' self._moved = False if position is not None: LOGGER.debug(_('Moving pointer to %s'), position) self._pointer.warp(self._screen, position[0], position[1]) self._moved = True else: LOGGER.debug(_('Not moving the pointer'))
def _exit_if_none_detected(self): if len(self._plural) == 0: message = _('Feature not detected: %s') % (self._name) if self._last_attempt_successful: self._last_attempt_successful = False LOGGER.info(message) raise FeatureNotFoundException(message) else: if not self._last_attempt_successful: self._last_attempt_successful = True message = _('Feature detected: %s') % (self._name) LOGGER.info(message)
def _load_plugin(self, class_string): try: LOGGER.info('loading %s', class_string) class_path = class_string.split('.') module = __import__('.'.join(class_path[:-1]), {}, {}, class_path[-1]) return getattr(module, class_path[-1])(self.config) except ImportError: LOGGER.error( _('Could not import plugin `%s`. ' + 'Check config file and PYTHONPATH.'), class_string) raise
class Camera(object): S_CAPTURE_OPEN_ERROR = _( 'Device #%d does not support video capture interface') S_CAPTURE_READ_ERROR = _('Error while capturing. Camera disconnected?') def __init__(self, config): self._config = config self._device = self._new_capture_device( config['camera']['device_index']) self.set_dimensions( config['camera']['width'], config['camera']['height'], ) @classmethod def _new_capture_device(cls, device_index): capture = cv2.VideoCapture(device_index) if not capture.isOpened(): capture.release() raise IOError(cls.S_CAPTURE_OPEN_ERROR % device_index) return capture def set_dimensions(self, width, height): self._device.set(FRAME_WIDTH, width) self._device.set(FRAME_HEIGHT, height) def read_image(self): ret, image = self._device.read() if not ret: raise IOError(self.S_CAPTURE_READ_ERROR) return Image(self._config, image)
def _load_plugin(self, class_string): try: LOGGER.info('loading %s', class_string) class_path = class_string.split('.') module = __import__( '.'.join(class_path[:-1]), {}, {}, class_path[-1] ) return getattr(module, class_path[-1])(self.config) except ImportError: LOGGER.error( _( 'Could not import plugin `%s`. ' + 'Check config file and PYTHONPATH.' ), class_string ) raise
def run(self, app): '''Called each pass of the loop.''' raise NotImplementedError(_('Must implement.'))