Exemplo n.º 1
0
    def _load_annotation_panel_and_label_iphotodraw(self, iphotodraw_path):
        """
        Load both panel and label annotation from iphotodraw formatted file
        :param iphotodraw_path:
        :return:
        """
        # create element tree object
        tree = ET.parse(iphotodraw_path)
        # get root element
        root = tree.getroot()

        shape_items = root.findall('./Layers/Layer/Shapes/Shape')

        # Read All Items (Panels and Labels)
        panel_items = []
        label_items = []
        for shape_item in shape_items:
            text_item = shape_item.find('./BlockText/Text')
            text = text_item.text.lower()
            if text.startswith('panel'):
                panel_items.append(shape_item)
            elif text.startswith('label'):
                label_items.append(shape_item)

        # Form individual panels
        panels = []
        for panel_item in panel_items:
            text_item = panel_item.find('./BlockText/Text')
            label = text_item.text
            words = label.split(' ')
            if len(words) is not 2:
                raise Exception(iphotodraw_path + ' ' + label +
                                ' panel is not correct')
            label = words[1]

            extent_item = panel_item.find('./Data/Extent')
            height = extent_item.get('Height')
            width = extent_item.get('Width')
            x = extent_item.get('X')
            y = extent_item.get('Y')
            panel_rect = [
                round(float(x)),
                round(float(y)),
                round(float(width)),
                round(float(height))
            ]

            panel = Panel(label, panel_rect, None)
            panels.append(panel)

        # Fill in label rects
        for panel in panels:
            for label_item in label_items:
                text_item = label_item.find('./BlockText/Text')
                label = text_item.text
                words = label.split(' ')
                if len(words) is not 2:
                    raise Exception(iphotodraw_path + ' ' + label +
                                    ' label is not correct')

                label = words[1]
                if label.lower() == panel.label.lower():
                    extent_item = label_item.find('./Data/Extent')
                    height = extent_item.get('Height')
                    width = extent_item.get('Width')
                    x = extent_item.get('X')
                    y = extent_item.get('Y')

                    label_rect = [
                        round(float(x)),
                        round(float(y)),
                        round(float(width)),
                        round(float(height))
                    ]
                    panel.label_rect = label_rect

        self.panels = panels
Exemplo n.º 2
0
    def _load_annotation_panel_and_label_iphotodraw(self, iphotodraw_path):
        """
        Load both panel and label annotation from iphotodraw formatted file
        :param iphotodraw_path:
        :return:
        """
        # create element tree object
        tree = ET.parse(iphotodraw_path)
        # get root element
        root = tree.getroot()

        shape_items = root.findall('./Layers/Layer/Shapes/Shape')

        # Read All Items (Panels and Labels)
        panel_items = []
        label_items = []
        for shape_item in shape_items:
            text_item = shape_item.find('./BlockText/Text')
            text = text_item.text.lower()
            if text.startswith('panel'):
                panel_items.append(shape_item)
            elif text.startswith('label'):
                label_items.append(shape_item)

        # Form individual panels
        panels = []
        for panel_item in panel_items:
            text_item = panel_item.find('./BlockText/Text')
            label = text_item.text
            words = label.split(' ')
            if len(words) is not 2:
                raise Exception(iphotodraw_path + ' ' + label + ' panel is not correct')
            label = words[1]

            extent_item = panel_item.find('./Data/Extent')
            height = extent_item.get('Height')
            width = extent_item.get('Width')
            x = extent_item.get('X')
            y = extent_item.get('Y')
            panel_rect = [round(float(x)), round(float(y)), round(float(width)), round(float(height))]

            panel = Panel(label, panel_rect, None)
            panels.append(panel)

        # Fill in label rects
        for panel in panels:
            for label_item in label_items:
                text_item = label_item.find('./BlockText/Text')
                label = text_item.text
                words = label.split(' ')
                if len(words) is not 2:
                    raise Exception(iphotodraw_path + ' ' + label + ' label is not correct')

                label = words[1]
                if label.lower() == panel.label.lower():
                    extent_item = label_item.find('./Data/Extent')
                    height = extent_item.get('Height')
                    width = extent_item.get('Width')
                    x = extent_item.get('X')
                    y = extent_item.get('Y')

                    label_rect = [round(float(x)), round(float(y)), round(float(width)), round(float(height))]
                    panel.label_rect = label_rect

        self.panels = panels