Skip to content

Commit f7dc811

Browse files
committed
minor changes
1 parent f12effa commit f7dc811

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

scripts/keypoint_density_evaluation.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def ProjectionsOfTriangulatedTiePoints(
1818

1919
image_projections = {}
2020
reconstruction = pycolmap.Reconstruction(model_path)
21+
average_tie_points = []
22+
average_tie_points_also_not_triangulated = []
2123

2224
for image in tqdm(reconstruction.images.values(), desc="Find projections that have a corresponding 3D tie points"):
2325
camera_id = image.camera_id
@@ -26,19 +28,27 @@ def ProjectionsOfTriangulatedTiePoints(
2628
height = camera.height
2729

2830
projections = []
31+
tot_tie_points = 0
32+
tot_tie_points_also_not_triangulated = 0
2933
for feature_idx, point2D in enumerate(image.points2D):
3034
#if point2D.has_point3D:
3135
if point2D.point3D_id < 1000000:
3236
#print(point2D.point3D_id);quit()
3337
#print(point2D.has_point3D.__getattribute__)
3438
#print(type(point2D.has_point3D))
3539
#quit()
40+
tot_tie_points += 1
41+
tot_tie_points_also_not_triangulated += 1
3642
x, y = point2D.xy
3743
x, y = x, (height-y)
3844
projections.append((image.image_id, (x,y), width, height))
45+
else:
46+
tot_tie_points_also_not_triangulated += 1
3947
image_projections[image] = projections
48+
average_tie_points.append(tot_tie_points)
49+
average_tie_points_also_not_triangulated.append(tot_tie_points_also_not_triangulated)
4050

41-
return image_projections
51+
return image_projections, np.mean(average_tie_points), np.mean(average_tie_points_also_not_triangulated)
4252

4353
def ComupteMetrics(
4454
output_dir: Path,
@@ -75,11 +85,11 @@ def ComupteMetrics(
7585
transform = from_origin(xmin, ymax, resolution, resolution)
7686

7787
zero_cells = np.count_nonzero(density_grid == 0)
78-
print(f"Image: {image_name}")
79-
print(f"Number of cells with zero density: {zero_cells}")
80-
print(f"Total number of cells: {rows * cols}")
88+
#print(f"Image: {image_name}")
89+
#print(f"Number of cells with zero density: {zero_cells}")
90+
#print(f"Total number of cells: {rows * cols}")
8191
covered_area = ((rows * cols)-zero_cells) / (rows * cols) * 100
82-
print(f"Percentage of cells with non zero density: {covered_area}%")
92+
#print(f"Percentage of cells with non zero density: {covered_area}%")
8393

8494
density_grid_normalized = zoom(
8595
density_grid_normalized,
@@ -107,20 +117,25 @@ def ComupteMetrics(
107117
parser = argparse.ArgumentParser(
108118
description="Export pairs in a txt file from a COLMAP database."
109119
)
110-
parser.add_argument("-d", "--database", type=Path, required=True, help="Path to COLMAP database.")
111-
parser.add_argument("-m", "--min_n_matches", type=int, required=True, help="Min number of matches that a pair should have after geometric verification.")
112-
parser.add_argument("-o", "--output", type=Path, required=True, help="Path to output folder.")
120+
#parser.add_argument("-d", "--database", type=Path, required=True, help="Path to COLMAP database.")
121+
#parser.add_argument("-m", "--min_n_matches", type=int, required=True, help="Min number of matches that a pair should have after geometric verification.")
122+
#parser.add_argument("-o", "--output", type=Path, required=True, help="Path to output folder.")
113123
parser.add_argument("-l", "--model", type=Path, required=True, help="Path to model folder.")
114124
args = parser.parse_args()
115125

116-
image_projections = ProjectionsOfTriangulatedTiePoints(model_path=args.model)
126+
image_projections, mean_tie_points, mean_tie_points_also_not_triangulated = ProjectionsOfTriangulatedTiePoints(model_path=args.model)
127+
print('Mean number of tie points per image:', mean_tie_points)
128+
print('Mean number of tie points per image also not triangulated:', mean_tie_points_also_not_triangulated)
129+
print(f"Inlier ratio: {mean_tie_points / mean_tie_points_also_not_triangulated}")
117130

118131
results = {}
132+
output_dir = Path(args.model) / "tie_points_density"
133+
output_dir.mkdir(parents=True, exist_ok=True)
119134

120135
for image in tqdm(image_projections, desc="Compute metrics"):
121136
#print(f"Image: {image.name} - Number of projections: {len(image_projections[image])}")
122137
image_name, covered_area = ComupteMetrics(
123-
output_dir=Path(args.output),
138+
output_dir=output_dir,
124139
image_name=image.name,
125140
projections=image_projections[image],
126141
scale_max_value=1,

0 commit comments

Comments
 (0)