Ejemplo n.º 1
0
class NosePlugin(interface.Plugin):
    def __init__(self, config):
        self._config = config
        self._nose_locator = NoseLocator()
        self._gui = Gui()
        self._location = None
        self._image = None

    def update_image(self, image):
        self._image = image
        try:
            point_image = self._nose_locator.locate(image)
            point_screen = self._convert_image_to_screen_point(*point_image)
            self._location = point_screen
        except FeatureNotFoundException:
            self._location = None

    def _convert_image_to_screen_point(self, image_x, image_y):
        image_width = self._image.get_width()
        image_height = self._image.get_height()
        percent_x = 1.0 * image_x // image_width
        percent_y = 1.0 * image_y // image_height
        screen_x = percent_x * self._gui.get_screen_width()
        screen_y = percent_y * self._gui.get_screen_height()
        half_width = self._gui.get_screen_width() // 2
        screen_x = (-1 * (screen_x - half_width)) + half_width
        return (screen_x, screen_y)

    def get_new_position(self):
        return self._location
Ejemplo n.º 2
0
class NosePlugin(interface.Plugin):
    def __init__(self, config):
        self._config = config
        self._nose_locator = NoseLocator()
        self._gui = Gui()
        self._location = None
        self._image = None

    def update_image(self, image):
        self._image = image
        try:
            point_image = self._nose_locator.locate(image)
            point_screen = self._convert_image_to_screen_point(*point_image)
            self._location = point_screen
        except FeatureNotFoundException:
            self._location = None

    def _convert_image_to_screen_point(self, image_x, image_y):
        image_width = self._image.get_width()
        image_height = self._image.get_height()
        percent_x = 1.0 * image_x // image_width
        percent_y = 1.0 * image_y // image_height
        screen_x = percent_x * self._gui.get_screen_width()
        screen_y = percent_y * self._gui.get_screen_height()
        half_width = self._gui.get_screen_width() // 2
        screen_x = (-1 * (screen_x - half_width)) + half_width
        return (screen_x, screen_y)

    def get_new_position(self):
        return self._location
Ejemplo n.º 3
0
 def __init__(self, config):
     LOGGER.info("Initializing")
     self.config = config
     self.image = None
     self.loop = Loop(config, self)
     self.gui = Gui(config)
     self.camera = Camera(config)
     self.pointer = Pointer(config)
     self.plugins = []
     self._assemble_plugins()
Ejemplo n.º 4
0
class App(object):

    def __init__(self, config):
        LOGGER.info("Initializing")
        self.config = config
        self.image = None
        self.loop = Loop(config, self)
        self.gui = Gui(config)
        self.camera = Camera(config)
        self.pointer = Pointer(config)
        self.plugins = []
        self._assemble_plugins()

    def _assemble_plugins(self):
        self._load_plugins()
        self._register_plugins_with_loop()

    def _load_plugins(self):
        for class_ in self.config['assembly']:
            self.plugins.append(self._load_plugin(class_))

    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 _register_plugins_with_loop(self):
        for plugin in self.plugins:
            self.loop.subscribe(plugin)

    def run(self):
        self.loop.start()
        self.gui.start()

    def stop(self):
        self.gui.stop()
        self.loop.stop()
Ejemplo n.º 5
0
class App(object):
    def __init__(self, config):
        LOGGER.info("Initializing")
        self.config = config
        self.image = None
        self.loop = Loop(config, self)
        self.gui = Gui(config)
        self.camera = Camera(config)
        self.pointer = Pointer(config)
        self.plugins = []
        self._assemble_plugins()

    def _assemble_plugins(self):
        self._load_plugins()
        self._register_plugins_with_loop()

    def _load_plugins(self):
        for class_ in self.config['assembly']:
            self.plugins.append(self._load_plugin(class_))

    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 _register_plugins_with_loop(self):
        for plugin in self.plugins:
            self.loop.subscribe(plugin)

    def run(self):
        self.loop.start()
        self.gui.start()

    def stop(self):
        self.gui.stop()
        self.loop.stop()
Ejemplo n.º 6
0
 def __init__(self, config):
     LOGGER.info("Initializing")
     self.config = config
     self.image = None
     self.loop = Loop(config, self)
     self.gui = Gui(config)
     self.camera = Camera(config)
     self.pointer = Pointer(config)
     self.plugins = []
     self._assemble_plugins()
Ejemplo n.º 7
0
 def __init__(self, config):
     self._config = config
     self._nose_locator = NoseLocator()
     self._gui = Gui()
     self._location = None
     self._image = None
Ejemplo n.º 8
0
 def __init__(self, config):
     self._config = config
     self._nose_locator = NoseLocator()
     self._gui = Gui()
     self._location = None
     self._image = None