Ejemplo n.º 1
0
def add_boxes(H,
              orig_image,
              confidences,
              boxes,
              use_stitching=False,
              rnn_len=1,
              min_conf=0.1,
              show_removed=True,
              tau=0.25,
              color_removed=(0, 0, 255),
              color_acc=(0, 0, 255)):
    image = np.copy(orig_image[0])
    num_cells = H["grid_height"] * H["grid_width"]
    boxes_r = np.reshape(boxes,
                         (-1, H["grid_height"], H["grid_width"], rnn_len, 6))
    confidences_r = np.reshape(
        confidences,
        (-1, H["grid_height"], H["grid_width"], rnn_len, H['num_classes']))
    cell_pix_size = H['region_size']
    all_boxes = [[[] for _ in range(H["grid_width"])]
                 for _ in range(H["grid_height"])]
    for n in range(rnn_len):
        for y in range(H["grid_height"]):
            for x in range(H["grid_width"]):
                bbox = boxes_r[0, y, x, n, :]
                abs_cx = bbox[0]
                abs_cy = bbox[1]
                abs_cz = bbox[2]
                w = bbox[3]
                h = bbox[4]
                d = bbox[5]
                conf = np.max(confidences_r[0, y, x, n, 1:])
                all_boxes[y][x].append(
                    Box(abs_cx, abs_cy, abs_cz, w, h, d, conf))

    all_boxes_r = [r for row in all_boxes for cell in row for r in cell]

    im = Image.fromarray(image.astype('uint8'))
    image = np.array(im).astype('float32')

    boxes = []
    for box in all_boxes_r:
        if box.true_confidence < min_conf:
            continue
        b = al.AnnoBox()
        b.x, b.y, b.z = box.cx, box.cy, box.cz
        b.w, b.h, b.d = box.width, box.height, box.depth
        b.score = box.true_confidence
        boxes.append(b)

    return image, boxes
Ejemplo n.º 2
0
def read_kitti_anno(label_file, detect_truck):
    """ Reads a kitti annotation file.

    Args:
    label_file: Path to file

    Returns:
      Lists of rectangels: Cars and don't care area.
    """
    labels = [line.rstrip().split(' ') for line in open(label_file)]
    box_list = []
    for label in labels:
        if not (label[0] == 'Car' or label[0] == 'Van' or
                label[0] == 'Truck' or label[0] == 'DontCare'):
            continue
        notruck = not detect_truck
        if notruck and label[0] == 'Truck':
            continue
        if label[0] == 'DontCare':
            class_id = -1
        else:
            class_id = 1
        x_dim=float(label[8])
        y_dim=float(label[9])
        z_dim=float(label[10])
        
        x_pos=float(label[11])
        y_pos=float(label[12])
        z_pos=float(label[13])

        if x_dim<0 or y_dim<0 or z_dim<0:
            continue

        object_rect = AnnoLib.AnnoBox(x=x_pos, y=y_pos, z=z_pos, w=x_dim, h=y_dim, d=z_dim)
        object_rect.classID = class_id
        box_list.append(object_rect)

    return box_list