cleaner saves
This commit is contained in:
parent
cf1f2d76a9
commit
1691cc10a2
48
src/draw.py
48
src/draw.py
|
@ -17,8 +17,6 @@ Z = f(X - 2, Y) + f(X + 2, Y)
|
|||
Z = (Z > 0.4).astype(np.float32)
|
||||
Z *= np.random.rand(*Z.shape)
|
||||
|
||||
|
||||
start = np.array([-3.75, -0.25])
|
||||
for i, x in enumerate(x_vals):
|
||||
for j, y in enumerate(y_vals):
|
||||
color = f"{hex(int(Z[j, i] * 255))[2:]}"
|
||||
|
@ -27,7 +25,6 @@ for i, x in enumerate(x_vals):
|
|||
else:
|
||||
color = "#" + 3 * color
|
||||
plt.fill([x, x + 0.1, x + 0.1, x], [y, y, y + 0.1, y + 0.1], color=color)
|
||||
# plt.plot(start[0], start[1], "ro")
|
||||
|
||||
nb_cams = 32
|
||||
cam_poses = np.array(
|
||||
|
@ -52,12 +49,12 @@ for i in range(nb_cams):
|
|||
plt.xlim(-7, 7)
|
||||
plt.ylim(-7, 7)
|
||||
plt.axis("equal")
|
||||
plt.show()
|
||||
|
||||
plt.savefig("data/peanut/peanut.png", dpi=300, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
plt.close()
|
||||
|
||||
# draw 1d image of the scene for each camera
|
||||
for i in range(13, 21):
|
||||
plt.figure(f"cam {i}")
|
||||
|
||||
# sort pixels by distance to camera
|
||||
cam_pose = cam_poses[i]
|
||||
pixels_dist = np.linalg.norm(np.array([X.flatten(), Y.flatten()]).T - cam_pose, axis=1)
|
||||
|
@ -66,14 +63,16 @@ for i in range(13, 21):
|
|||
x0 = -1
|
||||
x1 = 1
|
||||
|
||||
plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color="#003")
|
||||
plt.figure(f"img{i}")
|
||||
plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color="#000")
|
||||
plt.figure(f"mask{i}")
|
||||
plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color="#000")
|
||||
|
||||
for j in pixels_sort:
|
||||
x, y = X.flatten()[j], Y.flatten()[j]
|
||||
color = f"{hex(int(Z.flatten()[j] * 255))[2:]}"
|
||||
if color == "0":
|
||||
continue
|
||||
# color = "f"
|
||||
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
|
||||
|
@ -83,28 +82,21 @@ for i in range(13, 21):
|
|||
x0 = px[1, :].min()
|
||||
x1 = px[1, :].max()
|
||||
|
||||
plt.figure(f"img{i}")
|
||||
plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color=color)
|
||||
plt.figure(f"mask{i}")
|
||||
plt.fill([x0, x1, x1, x0], [0, 0, 0.2, 0.2], color="#fff")
|
||||
|
||||
plt.figure(f"img{i}")
|
||||
plt.xlim(-1, 1)
|
||||
plt.ylim(0, 0.2)
|
||||
plt.axis("off")
|
||||
plt.savefig(f"/tmp/Image{i:04}.png", dpi=300, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
# plt.close()
|
||||
plt.savefig(f"data/peanut/images/Image{i:04}.png", dpi=300, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
plt.close()
|
||||
|
||||
|
||||
RT = np.linalg.inv(cam2world_projs[i])[:-1, :]
|
||||
proj = RT @ np.array([start[0], start[1], 1.0])
|
||||
proj /= proj[0]
|
||||
plt.plot(proj[1], 0.1, "ro")
|
||||
|
||||
|
||||
plt.figure()
|
||||
frame = cv2.imread(f"/tmp/Image{i:04}.png")
|
||||
proj += np.array([0, 1.0])
|
||||
proj *= 0.5 * np.array([1, frame.shape[1]])
|
||||
proj = np.round(proj).astype(np.int32)
|
||||
plt.imshow(frame, cmap="gray")
|
||||
plt.plot(proj[1], frame.shape[0] / 2, "ro")
|
||||
|
||||
plt.show()
|
||||
|
||||
# plt.show()
|
||||
plt.figure(f"mask{i}")
|
||||
plt.xlim(-1, 1)
|
||||
plt.ylim(0, 0.2)
|
||||
plt.axis("off")
|
||||
plt.savefig(f"data/peanut/masks/Image{i:04}.png", dpi=300, bbox_inches="tight", pad_inches=0, transparent=True)
|
||||
plt.close()
|
||||
|
|
Loading…
Reference in a new issue