Co-authored-by: pejour <pejour@users.noreply.github.com>

Co-authored-by: Laureηt <laurent@fainsin.bzh>
This commit is contained in:
gdamms 2023-01-20 11:21:23 +01:00
parent d12aa5ce71
commit fdb94d2a55

View file

@ -4,7 +4,10 @@ from itertools import product
import pickle import pickle
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
VOXEL_SIZE = 3e-2
from borders import update_border
VOXEL_SIZE = 6e-2
X_MIN, X_MAX = -1.5, 1.5 X_MIN, X_MAX = -1.5, 1.5
Y_MIN, Y_MAX = -1.5, 1.5 Y_MIN, Y_MAX = -1.5, 1.5
Z_MIN, Z_MAX = -0.5, 0.5 Z_MIN, Z_MAX = -0.5, 0.5
@ -38,30 +41,37 @@ for k in range(nb_frame):
cam_points = cam_points[:,solid] cam_points = cam_points[:,solid]
points = points[solid,:] points = points[solid,:]
for cam_point in cam_points.T: # for cam_point in cam_points.T:
# cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255*is_in[k], 0, 255*(not is_in[k]))) # cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255*is_in[k], 0, 255*(not is_in[k])))
cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255, 0, 255)) # cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255, 0, 255))
for k in range(nb_frame): # for k in range(nb_frame):
frame = cv2.imread(f'/tmp/masks/Image{k:04}.png') # frame = cv2.imread(f'/tmp/masks/Image{k:04}.png')
with open(f"/tmp/cameras/{k:04d}.pickle", 'rb') as file: # with open(f"/tmp/cameras/{k:04d}.pickle", 'rb') as file:
proj_mat = pickle.load(file)["P"] # proj_mat = pickle.load(file)["P"]
cam_points = proj_mat @ points.T # cam_points = proj_mat @ points.T
cam_points /= cam_points[2,:] # cam_points /= cam_points[2,:]
cam_points = np.round(cam_points).astype(np.int32) # cam_points = np.round(cam_points).astype(np.int32)
for cam_point in cam_points.T: # for cam_point in cam_points.T:
# cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255*is_in[k], 0, 255*(not is_in[k]))) # # cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255*is_in[k], 0, 255*(not is_in[k])))
cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255, 0, 255)) # cv2.circle(frame, (cam_point[0], cam_point[1]), 2, (255, 0, 255))
cv2.imshow('Frame', frame) # cv2.imshow('Frame', frame)
cv2.waitKey(0) # cv2.waitKey(0)
voxel = np.zeros((int((X_MAX-X_MIN)/VOXEL_SIZE), int((Y_MAX-Y_MIN)/VOXEL_SIZE), int((Z_MAX-Z_MIN)/VOXEL_SIZE)))
idx = np.floor_divide(points[:, :3] - np.array([X_MIN, Y_MIN, Z_MIN]), VOXEL_SIZE).astype(int)
voxel[idx[:,0], idx[:,1], idx[:,2]] = 1
border = update_border(voxel)
# 3D plot the result # 3D plot the result
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111, projection='3d') ax = fig.add_subplot(111, projection='3d')
ax.scatter(points[:,0], points[:,1], points[:,2], c='r', marker='o') ax.scatter(np.where(border)[0], np.where(border)[1], np.where(border)[2], c='b', marker='o', s=1)
plt.axis("equal") plt.axis('equal')
plt.show() plt.show()