Exemple #1
0
def get_centered_bbox(pts_array, width, height, debug=True):
    '''
    given a set of points, return a set of bbox which are centered at the points
    
    parameters:
        pts_array:      2 x num_pts

    return:
        bbox:           N x 4 (TLBR format)

    '''
    
    if debug:
        assert is2dpts(pts_array) or is2dptsarray(pts_array) or is2dptsarray_occlusion(pts_array), 'the input points should have shape: 2 or 3 x num_pts vs %d x %s' % (pts_array.shape[0], pts_array.shape[1])

    if is2dpts(pts_array):
        xmin = pts_array[0] - np.ceil(width/2.0) + 1    
        ymin = pts_array[1] - np.ceil(height/2.0) + 1
    else: 
        xmin = pts_array[0, :] - np.ceil(width/2.0) + 1    
        ymin = pts_array[1, :] - np.ceil(height/2.0) + 1

    xmax = xmin + width - 1;
    ymax = ymin + height - 1;
    
    bbox = np.vstack((xmin, ymin, xmax, ymax))
    return np.transpose(bbox)
Exemple #2
0
def pts2bbox(pts, debug=True, vis=False):
    '''
    convert a set of 2d points to a bounding box

    parameter:  
        pts:    2 x N numpy array, N should >= 2

    return:
        bbox:   1 x 4 numpy array, TLBR format
    '''
    if debug:
        assert is2dptsarray(pts) or is2dptsarray_occlusion(pts), 'the input points should have shape: 2 or 3 x num_pts vs %d x %s' % (pts.shape[0], pts.shape[1])
        assert pts.shape[1] >= 2, 'number of points should be larger or equal than 2'

    bbox = np.zeros((1, 4), dtype='float32')
    bbox[0, 0] = np.min(pts[0, :])          # x coordinate of left top point
    bbox[0, 1] = np.min(pts[1, :])          # y coordinate of left top point
    bbox[0, 2] = np.max(pts[0, :])          # x coordinate of bottom right point
    bbox[0, 3] = np.max(pts[1, :])          # y coordinate of bottom right point
    
    if vis:
        fig = plt.figure()
        pts = imagecoor2cartesian(pts)
        plt.scatter(pts[0, :], pts[1, :], color='r')
        plt.scatter(bbox[0, 0], -bbox[0, 1], color='b')         # -1 is to convert the coordinate from image to cartesian
        plt.scatter(bbox[0, 2], -bbox[0, 3], color='b')
        plt.show()
        plt.close(fig)
    return bbox
Exemple #3
0
    def append(self,
               pts_root,
               pts_forward,
               pts_backward=None,
               pts_anno=None,
               image_prev_path=None,
               image_next_path=None,
               index=None):
        if index is None:
            index = self.length
        key = self.convert_index2key(index)
        if key in self.key_list:
            assert False, 'the data with index %d already exists' % index
        else:
            self.key_list.append(key)
            self.index_dict[key] = index

        if self.debug:
            assert is2dptsarray_occlusion(pts_root) or is2dptsarray(
                pts_root
            ), 'the shape of input point array %s in the root frame is not correct' % print_np_shape(
                pts_root)
            assert is2dptsarray_occlusion(pts_forward) or is2dptsarray(
                pts_forward
            ), 'the shape of input point array %s in the forward frame is not correct' % print_np_shape(
                pts_forward)
            assert is2dptsarray_occlusion(pts_backward) or is2dptsarray(
                pts_backward
            ) or pts_backward is None, 'the shape of input point array %s in the backward frame is not correct' % print_np_shape(
                pts_backward)
            assert is2dptsarray_occlusion(pts_anno) or is2dptsarray(
                pts_anno
            ) or pts_anno is None, 'the shape of input point array %s from the annotations is not correct' % print_np_shape(
                pts_anno)
            assert (isstring(image_prev_path) or image_prev_path is None) and (
                isstring(image_next_path) or
                image_next_path is None), 'the input image path is not correct'

        self.pts_root[key] = pts_root
        self.pts_forward[key] = pts_forward
        self.pts_backward[key] = pts_backward
        self.pts_anno[key] = pts_anno
        self.image_prev_path[key] = image_prev_path
        self.image_next_path[key] = image_next_path

        self.length += 1
Exemple #4
0
def pts_conversion_back_bbox(pts_array, bbox, debug=True):
    '''
    convert pts in the cropped image to the pts in the original image 

    parameters:
        bbox:       1 X 4 numpy array, TLBR or TLWH format
        pts_array:  2(3) x N numpy array, N should >= 1
    '''

    if debug:
        assert is2dptsarray(pts_array) or is2dptsarray_occlusion(pts_array), 'the input points should have shape: 2 or 3 x num_pts vs %d x %s' % (pts_array.shape[0], pts_array.shape[1])
        assert bboxcheck(bbox), 'the input bounding box is not correct'

    pts_array[0, :] = pts_array[0, :] + bbox[0, 0]
    pts_array[1, :] = pts_array[1, :] + bbox[0, 1]

    return pts_array