def execute(self, content):
        if not content.get(self.target):
            return content

        canvas = self.config["canvas"]
        image = cv2.imread(canvas)
        for r in content[self.target]:
            if not self.color and not r.color:
                raise InvalidColorConfig()
            if self.color:
                image = self.draw(image, r, self.color)
            else:
                image = self.draw(image, r, r.color)

        util.ensure_folder(self.config["output"])
        cv2.imwrite(self.config["output"], image)

        return content
    def execute(self, content):
        if not content.get(self.target):
            return content

        canvas = self.config["canvas"]
        image = cv2.imread(canvas)
        for r in content[self.target]:
            if not self.color and not r.color:
                raise InvalidColorConfig()
            if self.color:
                image = self.draw(image, r, self.color)
            else:
                image = self.draw(image, r, r.color)

        util.ensure_folder(self.config["output"])
        cv2.imwrite(self.config["output"], image)

        return content
Esempio n. 3
0
    def write(self, output_filename):
        try:
            import lxml.etree as ET
            self.has_lxml = True
        except ImportError:
            import xml.etree.cElementTree as ET

        self.output_filename = output_filename

        root = ET.Element("html")

        body = ET.SubElement(root, 'body')
        body.set("version", self.version)
        sc = ET.SubElement(body, "script")
        sc.set("language", self.config["language"])

        region_map = ET.SubElement(body, "map")
        region_map.set("name", "SynopticMap")
        self.preprocess_write_area(body)
        for i, b in enumerate(self.regions):
            name = b.name if b.name else "plz_replace_{}".format(str(i))

            if self.template:
                sc.text += self.template["select_formatter"].format(name=name)
            else:
                sc.text += """def {name}_onClick (in_obj, in_mousebutton, in_keymodifier): syn.select(in_mousebutton, in_keymodifier, '{name}')
""".format(name=name)

            self.write_shape(region_map, b, name)

        self.postprocess_write_area(body)

        img = ET.SubElement(body, "img")
        img.set("src", os.path.splitext(self.output_filename)[0] + ".png")
        img.set("usemap", "#SynopticMap")
        img.text = ""
        tree = ET.ElementTree(root)

        util.ensure_folder(self.output_filename)
        if self.has_lxml:
            tree.write(self.output_filename, pretty_print=True)
        else:
            tree.write(self.output_filename)