nik blender ptn
This commit is contained in:
parent
96741571a3
commit
73962d26be
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
.direnv
|
.direnv
|
||||||
data
|
data
|
||||||
|
assets
|
||||||
|
|
||||||
*.blend1
|
*.blend1
|
||||||
|
|
||||||
|
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix"
|
|
||||||
}
|
|
|
@ -15,6 +15,10 @@
|
||||||
poetry
|
poetry
|
||||||
python3
|
python3
|
||||||
python310Packages.numpy
|
python310Packages.numpy
|
||||||
|
(python310Packages.opencv4.override {
|
||||||
|
enableGtk2 = true;
|
||||||
|
gtk2 = pkgs.gtk2;
|
||||||
|
})
|
||||||
blender
|
blender
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,6 +46,9 @@ for i, (phi, theta) in enumerate(poses):
|
||||||
bpy.context.scene.objects["Empty"].rotation_euler[0] = phi
|
bpy.context.scene.objects["Empty"].rotation_euler[0] = phi
|
||||||
bpy.context.scene.objects["Empty"].rotation_euler[2] = theta
|
bpy.context.scene.objects["Empty"].rotation_euler[2] = theta
|
||||||
|
|
||||||
|
# fuck you blender and your stupid shit
|
||||||
|
bpy.context.view_layer.update()
|
||||||
|
|
||||||
# get camera matrices
|
# get camera matrices
|
||||||
P, K, RT = get_3x4_P_matrix_from_blender(cam)
|
P, K, RT = get_3x4_P_matrix_from_blender(cam)
|
||||||
|
|
||||||
|
@ -58,10 +61,7 @@ for i, (phi, theta) in enumerate(poses):
|
||||||
}, f)
|
}, f)
|
||||||
print(f"Saved camera matrices: {i:04d}.pickle")
|
print(f"Saved camera matrices: {i:04d}.pickle")
|
||||||
|
|
||||||
|
|
||||||
# set frame number
|
|
||||||
bpy.context.scene.frame_current = i
|
|
||||||
|
|
||||||
# render the frame
|
# render the frame
|
||||||
|
bpy.context.scene.frame_current = i
|
||||||
bpy.ops.render.render(write_still=False)
|
bpy.ops.render.render(write_still=False)
|
||||||
|
|
||||||
|
|
53
src/main.py
53
src/main.py
|
@ -3,39 +3,28 @@ import numpy as np
|
||||||
from itertools import product
|
from itertools import product
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
from matrices_reader import *
|
VOXEL_SIZE = 3e-2
|
||||||
|
X_MIN, X_MAX = -1.5, 1.5
|
||||||
|
Y_MIN, Y_MAX = -1.5, 1.5
|
||||||
|
Z_MIN, Z_MAX = -0.5, 0.5
|
||||||
|
|
||||||
PICKLE_PATH = "/tmp/pickle.truc"
|
nb_frame = 24
|
||||||
|
|
||||||
VOXEL_SIZE = 2e-2
|
|
||||||
X_MIN, X_MAX = -2.0, 2.0
|
|
||||||
Y_MIN, Y_MAX = -2.0, 2.0
|
|
||||||
Z_MIN, Z_MAX = -2.0, 2.0
|
|
||||||
|
|
||||||
with open(PICKLE_PATH, 'rb') as file:
|
|
||||||
projection_matrices = pickle.load(file)
|
|
||||||
nb_frame = len(projection_matrices) - 1
|
|
||||||
|
|
||||||
points = np.array([[x, y, z, 1.0] for x, y, z in product(
|
points = np.array([[x, y, z, 1.0] for x, y, z in product(
|
||||||
np.arange(X_MIN, X_MAX, VOXEL_SIZE),
|
np.arange(X_MIN, X_MAX, VOXEL_SIZE),
|
||||||
np.arange(Y_MIN, Y_MAX, VOXEL_SIZE),
|
np.arange(Y_MIN, Y_MAX, VOXEL_SIZE),
|
||||||
np.arange(Z_MIN, Z_MAX, VOXEL_SIZE))])
|
np.arange(Z_MIN, Z_MAX, VOXEL_SIZE))])
|
||||||
|
|
||||||
points_tor = np.array([[np.cos(theta), np.sin(theta), 0.0, 1.0] for theta, phi, r in product(
|
|
||||||
np.arange(0, 2*np.pi, 0.1),
|
|
||||||
np.arange(0, 2*np.pi, 0.1),
|
|
||||||
np.arange(0.0, 0.25, 0.1))])
|
|
||||||
|
|
||||||
mask = np.array([255, 255, 255])
|
mask = np.array([255, 255, 255])
|
||||||
# is_in = []
|
|
||||||
# p = [0.0, 1.1, 0.0]
|
test_point = [0, 0, 0, 1.0]
|
||||||
|
|
||||||
for k in range(nb_frame):
|
for k in range(nb_frame):
|
||||||
# points = np.array([p +[1.0]])
|
frame = cv2.imread(f'/tmp/masks/Image{k:04}.png')
|
||||||
|
|
||||||
|
with open(f"/tmp/cameras/{k:04d}.pickle", 'rb') as file:
|
||||||
|
proj_mat = pickle.load(file)["P"]
|
||||||
|
|
||||||
frame = cv2.imread(f'/tmp/masks/Image{k+1:04}.png')
|
|
||||||
proj_mat = projection_matrices[k]
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -48,14 +37,22 @@ for k in range(nb_frame):
|
||||||
cam_points = cam_points[:,solid]
|
cam_points = cam_points[:,solid]
|
||||||
points = points[solid,:]
|
points = points[solid,:]
|
||||||
|
|
||||||
# is_in.append(len(points) != 0)
|
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, 0, 255))
|
||||||
|
|
||||||
# points = np.array([p + [1.0]])
|
print(points.shape)
|
||||||
|
cv2.imshow('Frame', frame)
|
||||||
|
cv2.waitKey(0)
|
||||||
|
|
||||||
|
print("result")
|
||||||
|
|
||||||
for k in range(nb_frame):
|
for k in range(nb_frame):
|
||||||
frame = cv2.imread(f'/tmp/masks/Image{k+1:04}.png')
|
frame = cv2.imread(f'/tmp/masks/Image{k:04}.png')
|
||||||
proj_mat = projection_matrices[k]
|
|
||||||
|
with open(f"/tmp/cameras/{k:04d}.pickle", 'rb') as file:
|
||||||
|
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)
|
||||||
|
@ -65,4 +62,4 @@ for k in range(nb_frame):
|
||||||
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)
|
||||||
|
|
11
src/test.py
Normal file
11
src/test.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
nb_frame = 24
|
||||||
|
|
||||||
|
for k in range(nb_frame):
|
||||||
|
|
||||||
|
with open(f"/tmp/cameras/{k:04d}.pickle", 'rb') as file:
|
||||||
|
proj_mat = pickle.load(file)["P"]
|
||||||
|
|
||||||
|
print(k, proj_mat)
|
||||||
|
|
BIN
torus.blend
BIN
torus.blend
Binary file not shown.
Loading…
Reference in a new issue