Beispiel #1
0
    def test_compute_box_3d(self):
        # read in calib file and label file and mat file
        calib_frame = calib.read_calibration(self.test_data_calib_dir, 724513)
        objects = obj_utils.read_labels(self.test_data_label_dir, 5258)
        label_true = scipy.io.loadmat(self.test_data_dir + '/compute3d.mat')

        # compute
        corners_3d = obj_utils.compute_box_corners_3d(objects[0])
        corners, face_idx = obj_utils.project_box3d_to_image(
            corners_3d, calib_frame.p2)
        # compare data
        np.testing.assert_almost_equal(corners, label_true['corners'])

        orientation = obj_utils.compute_orientation_3d(objects[0], calib_frame.p2)

        # -1 for index in python vs matlab
        self.assertTrue((face_idx == label_true['face_idx']-1).all())

        # Test orientation
        self.assertAlmostEqual(orientation.all(),
                               label_true['orientation'].all())

        return
Beispiel #2
0
def draw_box_3d(ax,
                obj,
                p,
                show_orientation=True,
                color_table=None,
                line_width=3,
                double_line=True,
                box_color=None):
    """Draws the 3D boxes given the subplot, object label,
    and frame transformation matrix

    :param ax: subplot handle
    :param obj: object file to draw bounding box
    :param p:stereo frame transformation matrix

    :param show_orientation: optional, draw a line showing orientaion
    :param color_table: optional, a custom table for coloring the boxes,
        should have 4 values to match the 4 truncation values. This color
        scheme is used to display boxes colored based on difficulty.
    :param line_width: optional, custom line width to draw the box
    :param double_line: optional, overlays a thinner line inside the box lines
    :param box_color: optional, use a custom color for box (instead of
        the default color_table.
    """

    corners3d = obj_utils.compute_box_corners_3d(obj)
    corners, face_idx = obj_utils.project_box3d_to_image(corners3d, p)

    # define colors
    if color_table:
        if len(color_table) != 4:
            raise ValueError('Invalid color table length, must be 4')
    else:
        color_table = ["#00cc00", 'y', 'r', 'w']

    trun_style = ['solid', 'dashed']
    trc = int(obj.truncation > 0.1)

    if len(corners) > 0:
        for i in range(4):
            x = np.append(corners[0, face_idx[i, ]], corners[0, face_idx[i,
                                                                         0]])
            y = np.append(corners[1, face_idx[i, ]], corners[1, face_idx[i,
                                                                         0]])

            # Draw the boxes
            if box_color is None:
                box_color = color_table[int(obj.occlusion)]

            ax.plot(x,
                    y,
                    linewidth=line_width,
                    color=box_color,
                    linestyle=trun_style[trc])

            # Draw a thinner second line inside
            if double_line:
                ax.plot(x, y, linewidth=line_width / 3.0, color='b')

    if show_orientation:
        # Compute orientation 3D
        orientation = obj_utils.compute_orientation_3d(obj, p)

        if orientation is not None:
            x = np.append(orientation[0, ], orientation[0, ])
            y = np.append(orientation[1, ], orientation[1, ])

            # draw the boxes
            ax.plot(x, y, linewidth=4, color='w')
            ax.plot(x, y, linewidth=2, color='k')