Datasets:

Modalities:
Text
Formats:
csv
ArXiv:
Libraries:
Datasets
pandas
License:
Kuan Wei Huang commited on
Commit
94e2d92
·
1 Parent(s): 07ceac2

updated code for camera viz

Browse files
Files changed (2) hide show
  1. README.md +30 -5
  2. example.png +2 -2
README.md CHANGED
@@ -76,25 +76,50 @@ import numpy as np
76
  import pandas as pd
77
  from PIL import Image
78
 
79
- # load example data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  image_pairs_path = "image_pairs/train/image_pairs.csv"
81
  image_pairs = pd.read_csv(image_pairs_path)
82
  uid, scene_name, plan_path, photo_path = image_pairs.iloc[0]
83
 
 
84
  geometric_train_dir = "geometric/train/"
85
  corr_path = join(geometric_train_dir, "correspondences", f"{int(uid) // 1000}", f"{int(uid):06d}.npy")
86
  plan_corr, photo_corr = np.load(corr_path)
 
 
87
  camera_pose_path = join(geometric_train_dir, "camera_poses", f"{int(uid) // 1000}", f"{int(uid):06d}.npy")
88
- camera_orientation, camera_position, camera_intrinsics = np.load(camera_pose_path, allow_pickle=True)
89
  camera_orientation = np.array(camera_orientation.tolist(), dtype=float)
90
- Z = camera_orientation[:, 2]
91
  camera_position = np.array(camera_position)
92
 
 
93
  visual_dir = "visual/"
94
  plan = Image.open(join(visual_dir, scene_name, plan_path))
95
  photo = Image.open(join(visual_dir, scene_name, photo_path))
96
 
97
- # visualize correspondences and camera pose
98
  fig, axes = plt.subplots(1, 2, figsize=(12, 6))
99
  fig.suptitle(f"Scene name: {scene_name}", fontsize=16)
100
 
@@ -102,7 +127,7 @@ axes[0].imshow(plan)
102
  axes[0].set_title("Floor Plan")
103
  axes[0].scatter(plan_corr[:, 0], plan_corr[:, 1], c="r", s=1)
104
  scale = max(plan.size) * 0.05
105
- axes[0].arrow(camera_position[0], camera_position[2], Z[0] * scale, Z[2] * scale, color='b', head_width=scale, head_length=scale)
106
  axes[0].axis('off')
107
 
108
  axes[1].imshow(photo)
 
76
  import pandas as pd
77
  from PIL import Image
78
 
79
+ def draw_camera_frustum(ax, position, orientation, frustum_length, frustum_width, color='blue', alpha=0.3):
80
+ # Camera axes
81
+ forward = orientation[:, 2] # Z-axis
82
+ right = orientation[:, 0] # X-axis
83
+
84
+ # Near and far plane distances
85
+ near_len, far_len = frustum_length * 0.2, frustum_length
86
+ near_width, far_width = frustum_width * 0.2, frustum_width
87
+
88
+ # Corner points of the frustum
89
+ p = position
90
+ points = np.array([
91
+ p + forward * near_len - right * near_width / 2, # near left
92
+ p + forward * near_len + right * near_width / 2, # near right
93
+ p + forward * far_len + right * far_width / 2, # far right
94
+ p + forward * far_len - right * far_width / 2 # far left
95
+ ])
96
+
97
+ x, z = points[:, 0], points[:, 2]
98
+ ax.fill(x, z, color=color, alpha=alpha)
99
+ ax.plot(np.append(x, x[0]), np.append(z, z[0]), color=color)
100
+
101
+ # Load image pair
102
  image_pairs_path = "image_pairs/train/image_pairs.csv"
103
  image_pairs = pd.read_csv(image_pairs_path)
104
  uid, scene_name, plan_path, photo_path = image_pairs.iloc[0]
105
 
106
+ # Load correspondences
107
  geometric_train_dir = "geometric/train/"
108
  corr_path = join(geometric_train_dir, "correspondences", f"{int(uid) // 1000}", f"{int(uid):06d}.npy")
109
  plan_corr, photo_corr = np.load(corr_path)
110
+
111
+ # Load camera pose
112
  camera_pose_path = join(geometric_train_dir, "camera_poses", f"{int(uid) // 1000}", f"{int(uid):06d}.npy")
113
+ camera_orientation, camera_position, _ = np.load(camera_pose_path, allow_pickle=True)
114
  camera_orientation = np.array(camera_orientation.tolist(), dtype=float)
 
115
  camera_position = np.array(camera_position)
116
 
117
+ # Load floor plan and photo
118
  visual_dir = "visual/"
119
  plan = Image.open(join(visual_dir, scene_name, plan_path))
120
  photo = Image.open(join(visual_dir, scene_name, photo_path))
121
 
122
+ # Visualize
123
  fig, axes = plt.subplots(1, 2, figsize=(12, 6))
124
  fig.suptitle(f"Scene name: {scene_name}", fontsize=16)
125
 
 
127
  axes[0].set_title("Floor Plan")
128
  axes[0].scatter(plan_corr[:, 0], plan_corr[:, 1], c="r", s=1)
129
  scale = max(plan.size) * 0.05
130
+ draw_camera_frustum(axes[0], camera_position, camera_orientation, frustum_length=scale, frustum_width=scale, color='blue', alpha=0.3)
131
  axes[0].axis('off')
132
 
133
  axes[1].imshow(photo)
example.png CHANGED

Git LFS Details

  • SHA256: e5c55903c0ca1bbde717479218f7eba2ca15807ed65de2f80d7c11b2a8036cbe
  • Pointer size: 131 Bytes
  • Size of remote file: 689 kB

Git LFS Details

  • SHA256: e543a2ed7ad0080d39f9e07785424599796f0212ee6ba39bca34cfa48da26bd2
  • Pointer size: 131 Bytes
  • Size of remote file: 689 kB