Текущая простая конкатенация изображений:
Код: Выделить всё
def create_360_view(camera_left, camera_right, camera_rear):
left_img = camera_left.get_data()
right_img = camera_right.get_data()
rear_img = camera_rear.get_data()
combined_img = np.concatenate((left_img, right_img, rear_img), axis=1)
return combined_img
def display_image(display, image):
surface = pygame.surfarray.make_surface(image.swapaxes(0, 1))
display.blit(surface, (0, 0))
pygame.display.flip()
Результирующее изображение:
https://ibb.co/FnFhBcp
Я попробовал некоторые преобразования, как показано ниже, но при проецировании между изображениями есть промежутки:
Код: Выделить всё
def create_360_view(camera_left, camera_right, camera_rear):
left_img = camera_left.get_data()
right_img = camera_right.get_data()
rear_img = camera_rear.get_data()
height, width = left_img.shape[:2]
panorama_width = width * 3
panorama = np.zeros((height, panorama_width, 3), dtype=np.uint8)
place_image_cylindrical(panorama, left_img, 0, width)
place_image_cylindrical(panorama, right_img, width, width)
place_image_cylindrical(panorama, rear_img, 2*width, width)
return panorama
def place_image_cylindrical(panorama, img, start_x, width):
height, img_width = img.shape[:2]
cylinder_radius = width / (2 * np.pi / 3) # 120 degrees = 2π/3 radians
theta = np.linspace(-np.pi/3, np.pi/3, width)
h = np.arange(height) - height // 2
theta, h = np.meshgrid(theta, h)
x = np.round(cylinder_radius * np.tan(theta) + img_width / 2).astype(int)
y = np.round(h * np.cos(theta) + height / 2).astype(int)
mask = (x >= 0) & (x < img_width) & (y >= 0) & (y < height)
panorama_x = np.round(theta * width / (2*np.pi/3) + start_x).astype(int)
panorama_y = h + height // 2
valid_mask = mask & (panorama_x >= 0) & (panorama_x < panorama.shape[1]) & (panorama_y >= 0) & (panorama_y < panorama.shape[0])
panorama[panorama_y[valid_mask], panorama_x[valid_mask]] = img[y[valid_mask], x[valid_mask]]
https://ibb.co/Mk2FXtV
Подробнее здесь: https://stackoverflow.com/questions/789 ... fov-images