Re: Mapping Floor Plan Coordinates to Render/3DView Coordiantes
Code: Select all
object_location = np.array([749.2, 95, -2611.5])
camera_position = np.array([602.140686, 125, -4035.214600])
yaw = 0
pitch = 0
R_yaw = np.array([
[np.cos(yaw), 0, np.sin(yaw)],
[0, 1, 0],
[-np.sin(yaw), 0, np.cos(yaw)]
])
R_pitch = np.array([
[1, 0, 0],
[0, np.cos(pitch), -np.sin(pitch)],
[0, np.sin(pitch), np.cos(pitch)]
])
R = np.dot(R_pitch, R_yaw)
object_location_cam = object_location - camera_position
object_location_cam_rotated = np.dot(R, object_location_cam)
Code: Select all
image_width = 1024
image_height = 576
near = 0.1
far = 100.0
aspect_ratio = image_width / image_height
f = 1.0 / np.tan(fov / 2)
projection_matrix = np.array([
[f / aspect_ratio, 0, 0, 0],
[0, f, 0, 0],
[0, 0, -far / (far - near), (-far * near) / (far - near)],
[0, 0, -1, 0]
])
point_4d = np.append(object_location_cam_rotated, 1)
projected_point_4d = np.dot(projection_matrix, point_4d)
normalized_point = projected_point_4d[:3] / projected_point_4d[3]
x_pixel = int((normalized_point[0] * 0.5 + 0.5) * image_width)
y_pixel = int((1 - (normalized_point[1] * 0.5 + 0.5)) * image_height)
Code: Select all
image_width = 1024
image_height = 576
x_proj = (object_location_cam_rotated[0] / object_location_cam_rotated[2]) * (image_width / (2 * np.tan(fov / 2)))
y_proj = (object_location_cam_rotated[1] / object_location_cam_rotated[2]) * (image_height / (2 * np.tan(fov / 2)))
x_pixel = int(image_width / 2 - x_proj)
y_pixel = int(image_height / 2 - y_proj)
Code: Select all
object_location = np.array([1009.1, 0, -1071.6])
camera_position = np.array([3216.203613, 125, -1513.119751])
yaw = np.radians(90)
pitch = 0