def test_vector_to_camera_view(location, expected): from pylot.drivers.sensor_setup import CameraSetup camera_setup = CameraSetup('test_camera', 'sensor.camera.rgb', width=1920, height=1080, transform=Transform(Location(), Rotation())) location = Location(*location) assert all( np.isclose( location.to_camera_view( camera_setup.get_extrinsic_matrix(), camera_setup.get_intrinsic_matrix()).as_numpy_array(), expected)), "The camera transformation was not as expected."
def on_camera_msg(carla_image): game_time = int(carla_image.timestamp * 1000) print("Received camera msg {}".format(game_time)) camera_transform = pylot.utils.Transform.from_carla_transform( carla_image.transform) camera_setup = CameraSetup("rgb_camera", "sensor.camera.rgb", 800, 600, camera_transform, fov=90.0) global last_frame last_frame = CameraFrame.from_carla_frame(carla_image, camera_setup)
def test_get_pixel_locations(depth_frame, pixels, expected): height, width = depth_frame.shape camera_setup = CameraSetup('test_setup', 'sensor.camera.depth', width, height, Transform(location=Location(0, 0, 0), rotation=Rotation(0, 0, 0)), fov=90) depth_frame = DepthFrame(depth_frame, camera_setup) locations = depth_frame.get_pixel_locations(pixels) for i in range(len(pixels)): assert np.isclose(locations[i].x, expected[i].x), 'Returned x ' 'value is not the same as expected' assert np.isclose(locations[i].y, expected[i].y), 'Returned y ' 'value is not the same as expected' assert np.isclose(locations[i].z, expected[i].z), 'Returned z ' 'value is not the same as expected'
def test_depth_to_point_cloud(depth_frame, expected): height, width = depth_frame.shape camera_setup = CameraSetup('test_setup', 'sensor.camera.depth', width, height, Transform(location=Location(0, 0, 0), rotation=Rotation(0, 0, 0)), fov=90) depth_frame = DepthFrame(depth_frame, camera_setup) # Resulting unreal coordinates. point_cloud = depth_frame.as_point_cloud() for i in range(width * height): assert np.isclose(point_cloud[i][0], expected[i][0]), \ 'Returned x value is not the same as expected' assert np.isclose(point_cloud[i][1], expected[i][1]), \ 'Returned y value is not the same as expected' assert np.isclose(point_cloud[i][2], expected[i][2]), \ 'Returned z value is not the same as expected'
def test_point_cloud_get_pixel_location(lidar_points, pixel, expected): camera_setup = CameraSetup( 'test_setup', 'sensor.camera.depth', 801, 601, # width, height Transform(location=Location(0, 0, 0), rotation=Rotation(0, 0, 0)), fov=90) lidar_setup = LidarSetup('lidar', 'sensor.lidar.ray_cast', Transform(Location(), Rotation())) point_cloud = PointCloud(lidar_points, lidar_setup) location = point_cloud.get_pixel_location(pixel, camera_setup) assert np.isclose(location.x, expected.x), 'Returned x value is not the same ' 'as expected' assert np.isclose(location.y, expected.y), 'Returned y value is not the same ' 'as expected' assert np.isclose(location.z, expected.z), 'Returned z value is not the same ' 'as expected'
def on_lidar_msg(carla_pc): game_time = int(carla_pc.timestamp * 1000) print("Received lidar msg {}".format(game_time)) lidar_transform = pylot.utils.Transform.from_carla_transform( carla_pc.transform) lidar_setup = LidarSetup('lidar', lidar_type='sensor.lidar.ray_cast', transform=lidar_transform) point_cloud = PointCloud.from_carla_point_cloud(carla_pc, lidar_setup) camera_setup = CameraSetup("lidar_camera", "sensor.camera.depth", 800, 600, lidar_transform, fov=90.0) for (x, y) in pixels_to_check: pixel = pylot.utils.Vector2D(x, y) location = point_cloud.get_pixel_location(pixel, camera_setup) print("{} Computed using lidar {}".format((x, y), location)) global lidar_pc lidar_pc = point_cloud
def on_depth_msg(simulator_image): game_time = int(simulator_image.timestamp * 1000) print("Received depth camera msg {}".format(game_time)) depth_camera_transform = pylot.utils.Transform.from_simulator_transform( simulator_image.transform) camera_setup = CameraSetup("depth_camera", "sensor.camera.depth", 800, 600, depth_camera_transform, fov=90.0) depth_frame = DepthFrame.from_simulator_frame(simulator_image, camera_setup) for (x, y) in pixels_to_check: print("{} Depth at pixel {}".format((x, y), depth_frame.frame[y][x])) pos3d_depth = depth_frame.get_pixel_locations( [pylot.utils.Vector2D(x, y)])[0] print("{} Computed using depth map {}".format((x, y), pos3d_depth)) global depth_pc depth_pc = depth_frame.as_point_cloud()