def test_save_color_config(self): pm=VisionModule() pm.start(self.data) name = "all" path2res = find_resource("vision-color-config/auto-color-config") system("rm %s/%s.png" % (path2res, name)) pm.save_color_config(name) self.assertTrue(path.isfile("%s/%s.png" % (path2res, name)))
def load_connection_file(self): """ Lädt im idealfall die datei mit den Motorverbindungen """ try: path = find_resource('cables.yaml') with open(path, 'r') as f: self.cables = yaml.load(f) except IOError: self.debug.warning('Konnte die Resource cables.yaml nicht finden, abbruch!') except yaml.YAMLError as e: self.debug.warning("Fehler in der cables.yaml: \n %s" % e)
def load_help(self): """ Parse the yaml-file with the help information """ try: path = find_resource("record_help.yaml") with open(path, "r") as f: self.helpmap = yaml.load(f) ilog.debug("help-file successfully loaded") except IOError: ilog.warn("help-file could not be opened! - no help availiable") self.helpmap = None except yaml.YAMLError as e: ilog.warn("help-file could not be parsed! - no help availiable") ilog.warn("Error in help-file: %s" % e)
def obtain_palette(theme): """ Makes the I/O to load a theme """ try: path = find_resource("record_themes/" + theme) ilog.info("record color specification located as: %s" % path) with open(path, "r") as f: palette = yaml.load(f) ilog.debug("colors successfully loaded") return palette except IOError: ilog.warn("color-file could not be opened!") self.helpmap = None except yaml.YAMLError as e: ilog.warn("color-file could not be parsed!") ilog.warn("Error in color-file: %s" % e) return []
def load_color_config(self, which): # Farbraum-Konfiguration laden conf = numpy.zeros((256, 768), dtype=numpy.uint8) for idx, name in enumerate(("ball", "cyan", "yellow", "carpet", "white", "magenta")): if name != "carpet": # ignoring carpet, because of autoconfig debug_m(DebugLevel.LEVEL_4, "searching vision-color-config/%s/%s.png" % (which, name)) name = find_resource( "vision-color-config/%s/%s.png" % (which, name)) debug_m(DebugLevel.LEVEL_4, "Loading %s" % name) im = PngImage(name) mask = im.get_png_as_numpy_array() mask[mask != 0] = (1 << idx) conf += mask debug_m(DebugLevel.LEVEL_4, "vision-color-config/%s/%s.png geladen" % (which, name)) else: debug_m(DebugLevel.LEVEL_4, "vision-color-config/%s/%s.png ignoriert (autocolorconfig)" % (which, name)) return conf
def save_color_config(self, name="ball"): config = self.vision.get_color_config(name) path = find_resource("vision-color-config/auto-color-config") save_png_image("%s/%s.png" % (path, name), config)