コード例 #1
0
def draw_around_box(image: OrthographicImage, box: Dict[str, List[float]], draw_lines=False) -> None:
    bin_border = get_rect(size=box['size'], center=box['center'])
    image_border = get_rect(size=[10.0, 10.0, box['size'][2]])

    image_pose = Affine(image.pose)
    color_divisor = 255 * 255 if image.mat.dtype == np.float32 else 1

    bin_border_projection = [image.project((image_pose * p).to_array()) for p in bin_border]

    if draw_lines:
        color_direction = np.array([0, 255 * 255, 0]) / color_divisor  # Green

        for i in range(len(bin_border)):
            cv2.line(
                image.mat, tuple(bin_border_projection[i]),
                tuple(bin_border_projection[(i + 1) % len(bin_border)]),
                color_direction, 1
            )
    else:
        color = np.array([
            max(image.value_from_depth((image_pose * border.inverse()).z) for border in bin_border)
        ] * 3) / color_divisor

        image_border_projection = [image.project((image_pose * p).to_array()) for p in image_border]
        cv2.fillPoly(image.mat, np.array([image_border_projection, bin_border_projection]), color)
コード例 #2
0
def draw_around_box(image: OrthographicImage,
                    box: Dict[str, List[float]],
                    draw_lines=False) -> None:
    bin_border = get_rect(size=box['size'], center=box['center'])
    image_border = get_rect(size=[10.0, 10.0, box['size'][2]])

    image_pose = Affine(image.pose.x, image.pose.y, -image.pose.z,
                        image.pose.a, image.pose.b, image.pose.c)

    bin_border_projection = [image.project(image_pose * p) for p in bin_border]
    color = [
        max(
            image.value_from_depth((image_pose * border.inverse()).z)
            for border in bin_border)
    ] * 3

    if draw_lines:
        color_direction = (0, 255 * 255, 0)  # Green

        for i in range(len(bin_border)):
            cv2.line(image.mat, tuple(bin_border_projection[i]),
                     tuple(bin_border_projection[(i + 1) % len(bin_border)]),
                     color_direction, 1)
    else:
        image_border_projection = [
            image.project(image_pose * p) for p in image_border
        ]
        cv2.fillPoly(
            image.mat,
            np.array([image_border_projection, bin_border_projection]), color)
コード例 #3
0
def draw_line(
        image: OrthographicImage,
        action_pose: Affine,
        pt1: Affine,
        pt2: Affine,
        color,
        thickness=1,
        reference_pose=None,
    ) -> None:
    action_pose = Frames.get_pose_in_image(action_pose=action_pose, image_pose=Affine(image.pose), reference_pose=reference_pose)
    pt1_projection = tuple(image.project((action_pose * pt1).to_array()))
    pt2_projection = tuple(image.project((action_pose * pt2).to_array()))
    cv2.line(image.mat, pt1_projection, pt2_projection, color, thickness, lineType=cv2.LINE_AA)