После этого я хочу самостоятельно визуализировать сцену в Python. Мне это удалось, но положения кубов на изображениях не совпадают.

Я использую матрицу камеры 3x3 формы (3x3):
Код: Выделить всё
focal_length = 50
sensor_width = 20
sensor_height = 20
# Calculate the intrinsic matrix
fx = focal_length * width / sensor_width
fy = focal_length * height / sensor_height
cx = width / 2 # principal point is our image center
cy = height / 2
camera_matrix = np.array([
[fx, 0, cx],
[0, fy, cy],
[0, 0, 1]], np.float32)
Код: Выделить всё
angle_x = 90
angle_y = 0
angle_z = 45
rotation_matrix_x = np.array(
[
[1, 0, 0],
[0, np.cos(angle_x), -np.sin(angle_x)],
[0, np.sin(angle_x), np.cos(angle_x)],
]
)
rotation_matrix_y = np.array(
[
[np.cos(angle_y), 0, np.sin(angle_y)],
[0, 1, 0],
[-np.sin(angle_y), 0, np.cos(angle_y)],
]
)
rotation_matrix_z = np.array(
[
[np.cos(angle_z), -np.sin(angle_z), 0],
[np.sin(angle_z), np.cos(angle_z), 0],
[0, 0, 1],
]
)
rotation_matrix = rotation_matrix_x @ rotation_matrix_y @ rotation_matrix_z
А затем я определяю свою матрицу проекции следующим образом:
Код: Выделить всё
projection_matrix = camera_matrix @ np.hstack((rotation_matrix, translation_matrix))
Код: Выделить всё
new_row = np.array([[0, 0, 0, 1]], dtype=np.float32)
projection_matrix = np.vstack((projection_matrix, new_row)
создал куб [(4.75, 4.75, -1.25), (4.75, 5.25, -1.25) , (5,25, 5,25, -1,25), (5,25, 4,75, -1,25), (4,75, 4,75, -0,75), (4,75, 5,25, -0,75), (5,25, 5,25, -0,75), (5,25, 4,75, -0,75)] с центром: (5, 5, -1)
и преобразуем каждую 3D-точку в 2D:
Код: Выделить всё
def project_3d_to_2d(x, y, z, projection_matrix):
point_3d = np.array([x,y,z,1])
point_after_matrix = projection_matrix@point_3d
#Normalization of the projected point
point_after_matrix /= point_after_matrix[2] #z coordinate
points_2d = point_after_matrix[:2]
return points_2d
В Blender у меня есть следующие настройки:

Мой большой вопрос:
Могу ли я настроить камеру блендера так, чтобы она точно соответствовала матрице камеры, которую я использовал сам?
Или я могу перевести настройки камеры блендера в матрица моей камеры?
Спасибо вам огромное
Подробнее здесь: https://stackoverflow.com/questions/791 ... in-blender
Мобильная версия