コード例 #1
0
ファイル: populate.py プロジェクト: ajm/askdorotka
    def process_part(self, ele) :
        children = [e for e in ele.childNodes if e.nodeType == e.ELEMENT_NODE]
        a = AnnotationObject()
        err = False

        for c in children :
            if c.nodeName == 'name' :
                if len(c.childNodes) != 1 :
                    err = True
                    break
                a.name = c.childNodes[0].nodeValue

            elif c.nodeName == 'bndbox' :
                xmin,xmax,ymin,ymax = self.process_bndbox(c)
                a.xmin = xmin
                a.xmax = xmax
                a.ymin = ymin
                a.ymax = ymax

            else :
                raise CommandError('could not process node of type: %s' % c.nodeName)

            if err :
                raise CommandError('%s node was of length %d' % (c.nodeName, len(c.childNodes)))

        return a
コード例 #2
0
ファイル: populate.py プロジェクト: ajm/askdorotka
    def process_object(self, ele) :
        err = False
        parts = []
        tmp = None
        a = AnnotationObject()
        children = [e for e in ele.childNodes if e.nodeType == e.ELEMENT_NODE]

        for c in children :
            if c.nodeName == 'name' :
                if len(c.childNodes) != 1 :
                    err = True
                    break

                a.name = c.childNodes[0].nodeValue

            elif c.nodeName == 'pose' :
                if len(c.childNodes) != 1 :
                    err = True
                    break

                pose = c.childNodes[0].nodeValue
                tmp = pose
                if pose == 'Left' :
                    a.pose = 'L'
                elif pose == 'Right' :
                    a.pose = 'R'
                elif pose == 'Rear' :
                    a.pose = 'B'
                elif pose == 'Frontal' :
                    a.pose = 'F'
                elif pose == 'Unspecified' :
                    a.pose = 'U'

            elif c.nodeName == 'truncated' :
                if len(c.childNodes) != 1 :
                    err = True
                    break

                if c.childNodes[0].nodeValue == '0' :
                    a.truncated = False
                else :
                    a.truncated = True

            elif c.nodeName == 'difficult' :
                if len(c.childNodes) != 1 :
                    err = True
                    break
                
                if c.childNodes[0].nodeValue == '0' :
                    a.difficult = False 
                else :
                    a.difficult = True

            elif c.nodeName == 'bndbox' :
                xmin,xmax,ymin,ymax = self.process_bndbox(c)
                a.xmin = xmin
                a.xmax = xmax
                a.ymin = ymin
                a.ymax = ymax

            elif c.nodeName == 'part' :
                parts.append(self.process_part(c))

            else :
                raise CommandError('could not process node of type: %s' % c.nodeName)

            if err :
                raise CommandError('%s node was of length %d' % (c.nodeName, len(c.childNodes)))

        # treat pose as first-class feature
        p = copy.copy(a)
        p.name = tmp
        parts.append(a)
        parts.append(p)

        return parts