Skip to content

Commit

Permalink
formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ueber2y committed Oct 19, 2024
1 parent da1ff49 commit f01c23f
Show file tree
Hide file tree
Showing 23 changed files with 55 additions and 111 deletions.
3 changes: 2 additions & 1 deletion limap/line2d/SOLD2/model/model_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def get_heatmap_decoder(self):
def get_descriptor_decoder(self):
"""Get the descriptor decoder."""
if (
self.cfg["descriptor_decoder"] not in self.supported_descriptor_decoder
self.cfg["descriptor_decoder"]
not in self.supported_descriptor_decoder
):
raise ValueError(
"[Error] The descriptor decoder selection is not supported."
Expand Down
8 changes: 2 additions & 6 deletions limap/line2d/base_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def detect_all_images(self, output_folder, imagecols, skip_exists=False):
if self.visualize:
img = imagecols.read_image(img_id)
img = limapvis.draw_segments(img, segs, (0, 255, 0))
fname = os.path.join(
vis_folder, f"img_{img_id}_det.png"
)
fname = os.path.join(vis_folder, f"img_{img_id}_det.png")
cv2.imwrite(fname, img)
all_2d_segs = limapio.read_all_segments_from_folder(seg_folder)
all_2d_segs = {id: all_2d_segs[id] for id in imagecols.get_img_ids()}
Expand Down Expand Up @@ -306,9 +304,7 @@ def detect_and_extract_all_images(
if self.visualize:
img = imagecols.read_image(img_id)
img = limapvis.draw_segments(img, segs, (0, 255, 0))
fname = os.path.join(
vis_folder, f"img_{img_id}_det.png"
)
fname = os.path.join(vis_folder, f"img_{img_id}_det.png")
cv2.imwrite(fname, img)
all_2d_segs = limapio.read_all_segments_from_folder(seg_folder)
all_2d_segs = {id: all_2d_segs[id] for id in imagecols.get_img_ids()}
Expand Down
1 change: 0 additions & 1 deletion limap/optimize/extract_heatmaps_sold2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import limap.base as _base
import limap.line2d
import limap.util.io as limapio
Expand Down
4 changes: 1 addition & 3 deletions limap/optimize/extract_track_patches_s2dnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def extract_track_patches_s2dnet(
camview = imagecols.camview(img_id)
line2d_range = extractor.GetLine2DRange(track, img_id, camview)
line2d_collections[img_id].append([line2d_range, track_id])
limapio.check_makedirs(
os.path.join(output_dir, f"track{track_id}")
)
limapio.check_makedirs(os.path.join(output_dir, f"track{track_id}"))

# extract line patches for each image
for img_id in tqdm(imagecols.get_img_ids()):
Expand Down
12 changes: 3 additions & 9 deletions limap/pointsfm/colmap_sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ def run_colmap_sfm(
keypoints_in_order = []
for idx, img_id in enumerate(imagecols.get_img_ids()):
img = imagecols.read_image(img_id)
fname_to_save = os.path.join(
image_path, f"image{img_id:08d}.png"
)
fname_to_save = os.path.join(image_path, f"image{img_id:08d}.png")
cv2.imwrite(fname_to_save, img)
if keypoints is not None:
keypoints_in_order.append(keypoints[img_id])
Expand Down Expand Up @@ -251,15 +249,11 @@ def run_colmap_sfm_with_known_poses(
imagecols_tmp = copy.deepcopy(imagecols)
for idx, img_id in enumerate(imagecols.get_img_ids()):
img = imagecols.read_image(img_id)
fname_to_save = os.path.join(
image_path, f"image{img_id:08d}.png"
)
fname_to_save = os.path.join(image_path, f"image{img_id:08d}.png")
cv2.imwrite(fname_to_save, img)
if keypoints is not None:
keypoints_in_order.append(keypoints[img_id])
imagecols_tmp.change_image_name(
img_id, f"image{img_id:08d}.png"
)
imagecols_tmp.change_image_name(img_id, f"image{img_id:08d}.png")

# feature extraction and matching
run_hloc_matches(
Expand Down
4 changes: 1 addition & 3 deletions limap/pointsfm/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def ComputeNeighbors(

def compute_metainfos(cfg, model, n_neighbors=20):
# get neighbors
print(
f"Computing visual neighbors... (n_neighbors = {n_neighbors})"
)
print(f"Computing visual neighbors... (n_neighbors = {n_neighbors})")
neighbors = ComputeNeighbors(
model,
n_neighbors,
Expand Down
4 changes: 1 addition & 3 deletions limap/pointsfm/model_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def convert_colmap_to_visualsfm(colmap_model_path, output_nvm_file):
qvec, tvec = colmap_image.qvec, colmap_image.tvec
R = rotation_from_quaternion(qvec)
center = -R.transpose() @ tvec
f.write(
f" {qvec[0]} {qvec[1]} {qvec[2]} {qvec[3]}"
)
f.write(f" {qvec[0]} {qvec[1]} {qvec[2]} {qvec[3]}")
f.write(f" {center[0]} {center[1]} {center[2]}")
f.write(f" {k1} 0\n")
f.write("\n")
Expand Down
4 changes: 1 addition & 3 deletions limap/pointsfm/visualsfm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
def ReadModelVisualSfM(vsfm_path, nvm_file="reconstruction.nvm"):
input_file = os.path.join(vsfm_path, nvm_file)
if not os.path.exists(input_file):
raise ValueError(
f"Error! Input file {input_file} does not exist."
)
raise ValueError(f"Error! Input file {input_file} does not exist.")
with open(input_file) as f:
txt_lines = f.readlines()

Expand Down
4 changes: 1 addition & 3 deletions limap/runners/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ def undistort_images(
# start undistortion
if n_jobs == -1:
n_jobs = os.cpu_count()
print(
f"[LOG] Start undistorting images (n_images = {len(unload_ids)})..."
)
print(f"[LOG] Start undistorting images (n_images = {len(unload_ids)})...")
import cv2
import imagesize
import joblib
Expand Down
4 changes: 1 addition & 3 deletions limap/runners/functions_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def compute_2d_feature_points_sp(imagecols, output_path="tmp/featurepoints"):
### copy images to tmp folder
for img_id in imagecols.get_img_ids():
img = imagecols.read_image(img_id)
fname_to_save = os.path.join(
image_path, f"image{img_id:08d}.png"
)
fname_to_save = os.path.join(image_path, f"image{img_id:08d}.png")
cv2.imwrite(fname_to_save, img)

# run superpoint
Expand Down
1 change: 0 additions & 1 deletion limap/undistortion/undistort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import cv2
from _limap import _base, _undistortion

Expand Down
8 changes: 2 additions & 6 deletions limap/util/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def eval_imagecols(
imagecols, imagecols_gt, max_error=0.01, enable_logging=True
):
if enable_logging:
print(
f"[LOG EVAL] imagecols.NumImages() = {imagecols.NumImages()}"
)
print(f"[LOG EVAL] imagecols.NumImages() = {imagecols.NumImages()}")
print(
f"[LOG EVAL] imagecols_gt.NumImages() = {imagecols_gt.NumImages()}"
)
Expand Down Expand Up @@ -61,9 +59,7 @@ def eval_imagecols_relpose(
)
assert len(shared_img_ids) == imagecols.NumImages()
if enable_logging:
print(
f"[LOG EVAL] imagecols.NumImages() = {imagecols.NumImages()}"
)
print(f"[LOG EVAL] imagecols.NumImages() = {imagecols.NumImages()}")
print(
f"[LOG EVAL] imagecols_gt.NumImages() = {imagecols_gt.NumImages()}"
)
Expand Down
12 changes: 3 additions & 9 deletions limap/util/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ def save_l3dpp(folder, imagecols, all_2d_segs):
f.write(f"{n_segments}\n")
for line_id in range(n_segments):
line = segs[line_id]
f.write(
f"{line[0]} {line[1]} {line[2]} {line[3]}\n"
)
f.write(f"{line[0]} {line[1]} {line[2]} {line[3]}\n")
print(f"Writing for L3DPP: {fname}")


Expand Down Expand Up @@ -397,9 +395,7 @@ def read_lines_from_input(input_file):
General reader for lines
"""
if not os.path.exists(input_file):
raise ValueError(
f"Error! Input file/directory {input_file} not found."
)
raise ValueError(f"Error! Input file/directory {input_file} not found.")

# linetracks folder
if not os.path.isfile(input_file):
Expand Down Expand Up @@ -443,9 +439,7 @@ def save_txt_segments(folder, img_id, segs):
f.write(f"{n_segments}\n")
for line_id in range(n_segments):
line = segs[line_id]
f.write(
f"{line[0]} {line[1]} {line[2]} {line[3]}\n"
)
f.write(f"{line[0]} {line[1]} {line[2]} {line[3]}\n")


def read_txt_segments(folder, img_id):
Expand Down
6 changes: 5 additions & 1 deletion limap/visualize/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ def vis_vpresult(
colors = [[255, 0, 0]]
for line_id, line in enumerate(lines):
c = [255, 255, 255] # default color: white
if not vpres.HasVP(line_id) or vp_id >= 0 and vpres.labels[line_id] != vp_id:
if (
not vpres.HasVP(line_id)
or vp_id >= 0
and vpres.labels[line_id] != vp_id
):
if not show_original:
continue
else:
Expand Down
4 changes: 1 addition & 3 deletions runners/hypersim/Hypersim.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ def read_mpau(self, scene_dir):
if key in param_dict:
return float(param_dict[key])
else:
raise ValueError(
f"Key {key} not exists in {fname_metascene}"
)
raise ValueError(f"Key {key} not exists in {fname_metascene}")

def set_scene_id(self, scene_id):
self.scene_dir = os.path.join(self.data_dir, scene_id)
Expand Down
12 changes: 3 additions & 9 deletions runners/scannet/ScanNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def loadinfos(self):
index_list = np.arange(0, n_images, self.stride).tolist()

# load intrinsic
fname_meta = os.path.join(
self.scene_dir, f"{self.scene_id}.txt"
)
fname_meta = os.path.join(self.scene_dir, f"{self.scene_id}.txt")
K_orig, img_hw_orig = self.read_intrinsics(fname_meta)
h_orig, w_orig = img_hw_orig[0], img_hw_orig[1]
# reshape w.r.t max_image_dim
Expand All @@ -116,14 +114,10 @@ def loadinfos(self):
# get imname_list and cameras
self.imname_list, self.Rs, self.Ts = [], [], []
for index in index_list:
imname = os.path.join(
self.scene_dir, "color", f"{index}.jpg"
)
imname = os.path.join(self.scene_dir, "color", f"{index}.jpg")
self.imname_list.append(imname)

pose_txt = os.path.join(
self.scene_dir, "pose", f"{index}.txt"
)
pose_txt = os.path.join(self.scene_dir, "pose", f"{index}.txt")
R, T = self.read_pose(pose_txt)
self.Rs.append(R)
self.Ts.append(T)
Expand Down
8 changes: 3 additions & 5 deletions scripts/aachen_undistort.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def load_list_file(fname):
with open(fname, "r") as f:
with open(fname) as f:
lines = f.readlines()
imname_list, cameras = [], []
for line in lines:
Expand All @@ -35,7 +35,7 @@ def load_list_file(fname):
k1 = float(k[7])
K = np.array([[f, 0, cx], [0, f, cy], [0, 0, 1.0]])
camera = _base.Camera(
K, np.eye(3), np.zeros((3)), np.array([k1, 0, 0, 0, 0])
K, np.eye(3), np.zeros(3), np.array([k1, 0, 0, 0, 0])
)
imname_list.append(imname)
cameras.append(camera)
Expand All @@ -61,9 +61,7 @@ def process(image_list, cameras):
fx = camera_undistorted.K[0, 0]
cx, cy = camera_undistorted.K[0, 2], camera_undistorted.K[1, 2]
f.write(
"{0} SIMPLE_PINHOLE {1} {2} {3} {4} {5}\n".format(
imname_undist, w, h, fx, cx, cy
)
f"{imname_undist} SIMPLE_PINHOLE {w} {h} {fx} {cx} {cy}\n"
)


Expand Down
14 changes: 5 additions & 9 deletions scripts/eval_hypersim.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def report_error_to_GT(evaluator, lines, vis_err_th=None):
print("R: recall, P: precision")
for idx, threshold in enumerate(thresholds):
print(
"R / P at {0}mm: {1:.2f} / {2:.2f}".format(
int(threshold * 1000), list_recall[idx], list_precision[idx]
)
f"R / P at {int(threshold * 1000)}mm: {list_recall[idx]:.2f} / {list_precision[idx]:.2f}"
)
return evaluator

Expand All @@ -77,7 +75,7 @@ def read_ply(fname):
y = np.asarray(plydata.elements[0].data["y"])
z = np.asarray(plydata.elements[0].data["z"])
points = np.stack([x, y, z], axis=1)
print("number of points: {0}".format(points.shape[0]))
print(f"number of points: {points.shape[0]}")
return points


Expand Down Expand Up @@ -150,14 +148,14 @@ def eval_hypersim(
[line.as_array() for line in inlier_lines]
)
limapio.save_obj(
"tmp/inliers_th_{0:.4f}.obj".format(threshold), inlier_lines_np
f"tmp/inliers_th_{threshold:.4f}.obj", inlier_lines_np
)
outlier_lines = evaluator.ComputeOutlierSegs(lines, threshold)
outlier_lines_np = np.array(
[line.as_array() for line in outlier_lines]
)
limap.save_obj(
"tmp/outliers_th_{0:.4f}.obj".format(threshold),
f"tmp/outliers_th_{threshold:.4f}.obj",
outlier_lines_np,
)

Expand Down Expand Up @@ -286,9 +284,7 @@ def main():
[track.count_lines() for track in linetracks]
)
print(
"supporting images / lines: ({0:.2f} / {1:.2f})".format(
sup_image_counts.mean(), sup_line_counts.mean()
)
f"supporting images / lines: ({sup_image_counts.mean():.2f} / {sup_line_counts.mean():.2f})"
)


Expand Down
Loading

0 comments on commit f01c23f

Please sign in to comment.