projection peanut

This commit is contained in:
gdamms 2023-01-30 15:51:11 +01:00
parent 69ea7232dc
commit f615b89d29

View file

@ -21,7 +21,7 @@ for i, x in enumerate(x_vals):
for j, y in enumerate(y_vals): for j, y in enumerate(y_vals):
color = f"{hex(int(Z[j, i] * 255))[2:]}" color = f"{hex(int(Z[j, i] * 255))[2:]}"
if color == "0": if color == "0":
color = "#f00" color = "#003"
else: else:
color = "#" + 3 * color color = "#" + 3 * color
plt.fill([x, x + 0.1, x + 0.1, x], [y, y, y + 0.1, y + 0.1], color=color) plt.fill([x, x + 0.1, x + 0.1, x], [y, y, y + 0.1, y + 0.1], color=color)
@ -44,7 +44,6 @@ for i in range(nb_cams):
plt.text(cam_poses[i][0], cam_poses[i][1], str(i)) plt.text(cam_poses[i][0], cam_poses[i][1], str(i))
x = np.array([[0, 0, 1], [0.5, -0.2, 1], [0.5, 0.2, 1], [0, 0, 1]]).T x = np.array([[0, 0, 1], [0.5, -0.2, 1], [0.5, 0.2, 1], [0, 0, 1]]).T
x = cam2world_projs[i] @ x x = cam2world_projs[i] @ x
x /= x[2, :]
plt.plot(x[0, :], x[1, :], "r-") plt.plot(x[0, :], x[1, :], "r-")
@ -54,37 +53,38 @@ plt.axis("equal")
# draw 1d image of the scene for each camera # draw 1d image of the scene for each camera
for i in range(2): for i in [0, 8, 16, 24]:
plt.figure() plt.figure(f"cam {i}")
# sort pixels by distance to camera # sort pixels by distance to camera
cam_pose = cam_poses[i] cam_pose = cam_poses[i]
pixels_dist = np.linalg.norm(np.array([X.flatten(), Y.flatten()]).T - cam_pose, axis=1) pixels_dist = np.linalg.norm(np.array([X.flatten(), Y.flatten()]).T - cam_pose, axis=1)
pixels_sort = np.argsort(pixels_dist)[::-1] pixels_sort = np.argsort(pixels_dist)[::-1]
px = np.array([[-5, -5, 1], [5, -5, 1], [5, 5, 1], [-5, 5, 1]]).T x0 = -1
px = np.linalg.inv(cam2world_projs[i]) @ px x1 = 1
px /= px[1, :]
x0 = px[1, :].min() plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color="#003")
x1 = px[1, :].max()
plt.fill([x0, x1, x1, x0], [0, 0, 1, 1], color="r")
for j in pixels_sort: for j in pixels_sort:
x, y = X.flatten()[j], Y.flatten()[j] x, y = X.flatten()[j], Y.flatten()[j]
color = f"{hex(int(Z.flatten()[j] * 255))[2:]}" color = f"{hex(int(Z.flatten()[j] * 255))[2:]}"
if color == "0": if color == "0":
continue continue
# color = "f"
color = "#" + 3 * color color = "#" + 3 * color
px = np.array([[x, y, 1], [x + 0.1, y, 1], [x + 0.1, y + 0.1, 1], [x, y + 0.1, 1]]).T px = np.array([[x, y, 1], [x + 0.1, y, 1], [x + 0.1, y + 0.1, 1], [x, y + 0.1, 1]]).T
px = np.linalg.inv(cam2world_projs[i]) @ px px = np.linalg.inv(cam2world_projs[i]) @ px
px /= px[1, :] px /= px[0, :]
x0 = px[1, :].min() x0 = px[1, :].min()
x1 = px[1, :].max() x1 = px[1, :].max()
plt.fill([x0, x1, x1, x0], [0, 0, 1, 1], color=color) plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color=color)
plt.axis("equal") plt.xlim(-1, 1)
plt.ylim(0, 0.2)
plt.axis("off")
plt.savefig(f"data/peanut/images/Image{i:04}.png", dpi=300, bbox_inches="tight", pad_inches=0, transparent=True)
plt.show() plt.show()