From 745ef001e66c11a87165ffb65d19d8a1ebdd0896 Mon Sep 17 00:00:00 2001 From: Mark Yu Date: Fri, 9 Dec 2022 12:37:49 +0100 Subject: [PATCH] Fix visualize utils and add scaled obj output function for 3d lines visualization (#35) * Fix visualize utils * Add output option for visualizing 3d lines with scaling * change output logic, add help description * minor. Co-authored-by: B1ueber2y --- limap/visualize/vis_utils.py | 6 +++++- visualize_3d_lines.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/limap/visualize/vis_utils.py b/limap/visualize/vis_utils.py index 542d2e23..00118d66 100644 --- a/limap/visualize/vis_utils.py +++ b/limap/visualize/vis_utils.py @@ -4,7 +4,7 @@ import matplotlib import matplotlib.pyplot as plt import seaborn as sns - +import copy def random_color(): r = int(255 * np.random.rand()) @@ -14,6 +14,7 @@ def random_color(): def draw_points(image, points, color=None, thickness=1): + image = copy.deepcopy(image) for p in points: c = random_color() if color is None else color pos_x, pos_y = int(round(p[0])), int(round(p[1])) @@ -22,6 +23,7 @@ def draw_points(image, points, color=None, thickness=1): def draw_segments(image, segments, color=None, thickness=1, endpoints=True): + image = copy.deepcopy(image) for s in segments: c = random_color() if color is None else color p1 = (int(s[0]), int(s[1])) @@ -36,6 +38,7 @@ def draw_segments(image, segments, color=None, thickness=1, endpoints=True): def draw_salient_segments(image, segments, saliency, color1=(0, 255, 0), color2=(0, 0, 255), thickness=1, endpoints=True): assert len(segments) == len(saliency) + image = copy.deepcopy(image) max_saliency, min_saliency = np.max(saliency), np.min(saliency) for s, s_saliency in zip(segments, saliency): r = (s_saliency - min_saliency) / (max_saliency - min_saliency) @@ -52,6 +55,7 @@ def draw_salient_segments(image, segments, saliency, color1=(0, 255, 0), color2= def draw_multiscale_segments(img, segs, color=None, endpoints=True, thickness=2): + img = copy.deepcopy(img) for s in segs: mycolor = random_color() if color is None else color octave, l = s[0] diff --git a/visualize_3d_lines.py b/visualize_3d_lines.py index da52331b..ade24966 100644 --- a/visualize_3d_lines.py +++ b/visualize_3d_lines.py @@ -16,6 +16,7 @@ def parse_args(): arg_parser.add_argument('--use_robust_ranges', action='store_true', help="whether to use computed robust ranges") arg_parser.add_argument('--scale', type=float, default=1.0, help="scaling both the lines and the camera geometry") arg_parser.add_argument('--cam_scale', type=float, default=1.0, help="scale of the camera geometry") + arg_parser.add_argument('--output_dir', type=str, default=None, help="if set, save the scaled lines in obj format") args = arg_parser.parse_args() return args @@ -51,6 +52,8 @@ def main(args): raise ValueError("Error! Input file {0} is not valid".format(args.imagecols)) imagecols = _base.ImageCollection(limapio.read_npy(args.imagecols).item()) vis_reconstruction(linetracks, imagecols, mode=args.mode, n_visible_views=args.n_visible_views, ranges=ranges, scale=args.scale, cam_scale=args.cam_scale) + if args.output_dir is not None: + limapio.save_obj(args.output_dir, lines) if __name__ == '__main__': args = parse_args()