Angtian / NeMo

The official implementation of NeMo: Neural Mesh Models of Contrastive Features for Robust 3D Pose Estimation [ICLR-2021]. https://arxiv.org/pdf/2101.12378.pdf
88 stars 13 forks source link

"Include method supposed to be point or bbox" error running PrepareData.sh with BboxTools 1.0.2 #1

Closed tomforge closed 3 years ago

tomforge commented 3 years ago

https://github.com/Angtian/NeMo/blob/11fe2101d35ab9eac2a2f813f33d95d616dc5d02/code/lib/MeshMemoryMap.py#L60

BBox2D.include in BboxTools 1.0.2 seems to only accept single points or a Bbox2D object (code pasted below). points_2d is a numpy array of points, which causes an error at the line above, so generate3Dpascal3D.py is failing to generate any annotations.

def include(self, other):
        """
        Check if other is inside this box. Notice include means strictly include, other could not place at the boundary
        of this bbox.
        :param other: (Bbox2D or tuple of int) bbox or point
        :return: (bool) True or False
        """
        if type(other) == Bbox2D:
            out = True
            for i in range(2):
                if self.bbox[i][0] > other.bbox[i][0]:
                    out = False
                if self.bbox[i][1] < other.bbox[i][1]:
                    out = False
            return out

        if type(other) == tuple and len(other) == 2:
            if other[0] < self.bbox[0][0] or other[0] >= self.bbox[0][1]:
                return False
            if other[1] < self.bbox[1][0] or other[1] >= self.bbox[1][1]:
                return False
            return True
        raise Exception('Include method suppose to be point or bbox, but got %s' % str(other))
Angtian commented 3 years ago

Thanks for proposing this issue. It seems there is some issue with my package version management (I have uploaded an older version of BboxTools). To fix this, add function into MeshMemoryMap.py (already modified in this repo):

def box_include_2d(self_box, other):
    return np.logical_and(np.logical_and(self_box.bbox[0][0] <= other[:, 0], other[:, 0] < self_box.bbox[0][1]),
                          np.logical_and(self_box.bbox[1][0] <= other[:, 1], other[:, 1] < self_box.bbox[1][1]))

And change line 60 as:

if_visible = np.logical_and(if_visible, box_include_2d(box_ori, points_2d))