cvg / limap

A toolbox for mapping and localization with line features.
BSD 3-Clause "New" or "Revised" License
661 stars 67 forks source link

Visualize 2d lines on top of original image, help with scaling factor #44

Closed awarebayes closed 10 months ago

awarebayes commented 10 months ago

Hello, I am looking for a way to visualize 2d lines on top of the image. My code is as the following:

import limap.util.io as limapio
import json
from tqdm import tqdm
import pandas as pd
import cv2
from pathlib import Path

name = "global"

def track_is_good(track, bb=50):
    points = track.line.start, track.line.end
    return all([(point < bb).all() and (point > -bb).all() for point in points])

def load_tracks():
    _, tracks = limapio.read_lines_from_input(f"/files/static/storage/reconstructions/{name}/outputs/lines/finaltracks")
    assert tracks
    tracks = list(filter(track_is_good, tracks))
    return tracks

image_list = f"/files/static/storage/reconstructions/{name}/outputs/lines/image_list.txt"

with open(image_list) as f:
    lines = f.readlines()
    lines = lines[1:]
    image_id_to_path = dict()
    for x in lines:
        x = x.split(', ')
        image_id_to_path[int(x[0])] = x[1].strip()

tracks = load_tracks()
for image_id in list(image_id_to_path.keys())[:10]:
    image_path = image_id_to_path[image_id]
    lines_2d = []
    for track in tracks:
        if image_id in track.image_id_list:
            for image_idx, image_id_i in enumerate(track.image_id_list):
                if image_id_i == image_id:
                    lines_2d.append(track.line2d_list[image_idx])
    image = cv2.imread(image_path)
    for line in lines_2d:
        start = line.start.astype(int) 
        end = line.end.astype(int) 
        image = cv2.line(image, start, end, (0, 255, 0), 3)
    file_name = Path(image_path).name
    cv2.imwrite(f"temp/{file_name}", image)

print("a")

However, when I open an image I get this misalignment:

image

You can see, the overall result is correct, just that scaled by some factor. How do I unscale it? Didn't find anything like target_resize_test parameter in the triangulation configs

awarebayes commented 10 months ago

Ah I can see that: max_image_dim: 1600