Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lidar label #8668

Open
Vish19-code opened this issue Feb 11, 2025 · 11 comments
Open

lidar label #8668

Vish19-code opened this issue Feb 11, 2025 · 11 comments

Comments

@Vish19-code
Copy link

lidar_position = carla.Transform(carla.Location(x=-46.17, y=-73.55, z=3.4), carla.Rotation(pitch=0, yaw=0))

i am placing my lidar in this location and want label data 3d object detection so it is possible and how i try but they not giving right data in the label file of the object.

lidar_bp = blueprint_library.find('sensor.lidar.ray_cast')
lidar_bp.set_attribute('range', '50') # Adjust range as needed for coverage
lidar_bp.set_attribute('rotation_frequency', '10')
lidar_bp.set_attribute('channels', '32')

@PatrickPromitzer
Copy link

Hi,
The "sensor.lidar.ray_cast" doesn't have an label.
https://carla.readthedocs.io/en/0.9.15/ref_sensors/#lidar-sensor
Array of 32-bits floats (XYZI of each point).

You are looking for "sensor.lidar.ray_cast_semantic"
https://carla.readthedocs.io/en/0.9.15/ref_sensors/#semantic-lidar-sensor

  • Array containing the point cloud with instance and semantic information. For each point, four 32-bits floats are stored. XYZ coordinates.
  • cosine of the incident angle.
  • Unsigned int containing the index of the object hit.
  • Unsigned int containing the semantic tag of the object it.

@Vish19-code
Copy link
Author

hello,

Thank you for the information.

i have also another problem i am label cyclist but it does not shown in label file so what should i do for cyclist and two wheeler participant

if "vehicle.motorcycle" in obj.type_id or "vehicle.bicycle" in obj.type_id or "vehicle.two_wheel" in obj.type_id:
category = "Cyclist"
elif "vehicle" in obj.type_id:
category = "Car"
elif "walker.pedestrian" in obj.type_id:
category = "Pedestrian"
else:
print(f"❌ Object {obj.type_id} is not a recognized category")
continue

is this true?

@PatrickPromitzer
Copy link

Which Carla version are you using?
The tags changed at version 0.9.14

Image

Your script looks right, but you should test it against the whole blueprint list to be sure.

@Vish19-code
Copy link
Author

CARLA Version: 0.9.15

i am using this version but same problem cyclic is not able to label

what is the problem ?

@PatrickPromitzer
Copy link

With the "sensor.lidar.ray_cast_semantic" sensor, you always get an label back, even it it is tag 0.
The sensor give you numbers and not strings.

What do you get back?
How does your code look like?
How do you convert the sensor data?

@Vish19-code
Copy link
Author

hello,

def spawn_actors(world, blueprint_library, num_vehicles=50, num_pedestrians=20, num_cyclists=10, moving_ratio=0.5):
"""Spawn vehicles, pedestrians (both stable and moving), and cyclists in the simulation."""

spawn_points = world.get_map().get_spawn_points()
if not spawn_points:
    raise RuntimeError("No spawn points available in the map.")

vehicles_list = []
pedestrians_list = []
controllers_list = []
cyclists_list = []

# Spawn vehicles
vehicle_blueprints = blueprint_library.filter("vehicle.*")
for _ in range(num_vehicles):
    blueprint = random.choice(vehicle_blueprints)
    spawn_point = random.choice(spawn_points)
    vehicle = world.try_spawn_actor(blueprint, spawn_point)
    if vehicle:
        vehicles_list.append(vehicle)
        vehicle.set_autopilot(True)
print(f"✅ {len(vehicles_list)} vehicles spawned.")

# Spawn pedestrians (both stable and moving)
pedestrian_blueprints = blueprint_library.filter("walker.pedestrian.*")
walker_controller_bp = blueprint_library.find('controller.ai.walker')

pedestrian_locations = [
    carla.Location(x=-46.171577, y=-73.556618, z=0.254254),
    carla.Location(x=-34.449154, y=-51.020489, z=0.254255),
    carla.Location(x=-59.242249, y=-51.498371, z=0.254254),
    carla.Location(x=-50.171577, y=-73.556618, z=0.254254),
    carla.Location(x=-80.449154, y=-51.020489, z=0.254255),
    carla.Location(x=-30.242249, y=-51.498371, z=0.254254)
]

num_moving = int(len(pedestrian_locations) * moving_ratio)  # Number of moving pedestrians
num_stable = len(pedestrian_locations) - num_moving  # Number of stable pedestrians

print(f"🚶 Spawning {num_stable} stable pedestrians and {num_moving} moving pedestrians.")

for i, loc in enumerate(pedestrian_locations):
    blueprint = random.choice(pedestrian_blueprints)
    pedestrian = world.try_spawn_actor(blueprint, carla.Transform(loc))
    if pedestrian:
        pedestrians_list.append(pedestrian)

        # Attach AI Controller only for moving pedestrians
        if i < num_moving:
            controller = world.spawn_actor(walker_controller_bp, carla.Transform(), pedestrian)
            controllers_list.append(controller)
            controller.start()
            controller.go_to_location(world.get_random_location_from_navigation())
            controller.set_max_speed(random.uniform(0.8, 1.5))  # Random speed between 0.8m/s and 1.5m/s

print(f"✅ {len(pedestrians_list)} pedestrians spawned ({len(controllers_list)} moving).")

# Spawn cyclists at random locations
cyclist_blueprints = blueprint_library.filter("vehicle.bicycle.*")
if not cyclist_blueprints:
    print("⚠️ No cyclist blueprints found.")
else:
    for _ in range(num_cyclists):
        blueprint = random.choice(cyclist_blueprints)
        spawn_point = random.choice(spawn_points)
        cyclist = world.try_spawn_actor(blueprint, spawn_point)
        if cyclist:
            cyclists_list.append(cyclist)
            cyclist.set_autopilot(True)
    print(f"✅ {len(cyclists_list)} cyclists spawned at random locations.")

return vehicles_list, pedestrians_list, controllers_list, cyclists_list

and this how i am label the data

def save_3d_labels(world, frame_id, lidar, lidar_range, cameras):
"""Save 3D bounding boxes for objects detected by LiDAR and cameras."""
output_dir = "data/custom/labels"
os.makedirs(output_dir, exist_ok=True)
print(f"🔍 Saving 3D labels for frame {frame_id}")
actors = world.get_actors()
objects = list(actors.filter("vehicle.")) + list(actors.filter("walker.pedestrian.")) + list(actors.filter("vehicle.bicycle.*"))
print(f"📌 Detected {len(objects)} objects")

labels = []
for obj in objects:
    bbox = obj.bounding_box
    loc = obj.get_transform().location
    yaw = obj.get_transform().rotation.yaw  

    # Calculate distance from LiDAR sensor
    distance = loc.distance(lidar.get_transform().location)
    if distance > lidar_range:
        print(f"⚠️ Object {obj.type_id} is outside the LiDAR range.")
        continue

    if "vehicle.motorcycle" in obj.type_id or "vehicle.bicycle" in obj.type_id or "vehicle.*two_wheel*" in obj.type_id:
        category = "Cyclist"
    elif "vehicle" in obj.type_id:
        category = "Car"
    elif "walker.pedestrian" in obj.type_id:
        category = "Pedestrian"
    else:
        print(f"❌ Object {obj.type_id} is not a recognized category")
        continue  

    # Check if the object is detected by any camera
    detected_by_camera = False
    for camera in cameras:
        if is_object_in_camera_view(camera, obj):
            detected_by_camera = True
            break

    # Transform global coordinates to sensor coordinates
    sensor_coords = transform_to_sensor_coordinates(obj, lidar)
    label_str = f"{sensor_coords[0]:.2f} {sensor_coords[1]:.2f} {sensor_coords[2]:.2f} {bbox.extent.x*2:.2f} {bbox.extent.y*2:.2f} {bbox.extent.z*2:.2f} {yaw:.2f} {category}"
    print(f"📝 Generated 3D label: {label_str}")
    labels.append(label_str)

print(f"✅ {len(labels)} objects labeled in 3D for LiDAR")
if labels:
    with open(f"{output_dir}/{frame_id:06d}.txt", "w") as f:
        f.writelines("\n".join(labels) + "\n")
    print(f"💾 3D labels saved to {output_dir}/{frame_id:06d}.txt")
else:
    print("⚠️ No labels generated for 3D objects")

according above spwam vehicle i am not able to pedestrial walking it is stable with one location as pedestrial is in random location place in road therfore i place in particular location and it does not move as well

@PatrickPromitzer
Copy link

This code doesn't use LIDAR data.

I can't tell the functionality of the function transform_to_sensor_coordinates(obj, lidar), but the only part you are using is the location of the sensor.
"vehicle.motorcycle", "vehicle.bicycle", and "vehicle.two_wheel" are not an blueprints that exists.
You say the LIDAR labels are wrong, but you are using the blueprint Ids.

Before we continue, write down what you want to do, because it doesn't look like your code fit to the question you are asking.
Check the data in different steps, because you filter the actors without knowing the actor values.

@Vish19-code
Copy link
Author

hello,

i am using infrastructure based 1 lidar and 2 cameras in and i have to label participants and make 3D label in label as well as calibration file like car, pedestrial and cyclic.

In that i have those problem that cyclic is not able to label they recognised as car and label it in label file is car not cyclic

Image

@PatrickPromitzer
Copy link

Because, vehicle.* is everything with 2 and 4 wheels, and the first if statement doesn't work.

https://carla.readthedocs.io/en/0.9.15/python_api/#carlaactor
you need actor.semantic_tags

@Vish19-code
Copy link
Author

hello,

Thank you it works

i have another problem that i spawn the pedestrian but it going in the road like random location not in side road like regular traffic participant so what should i do?

@PatrickPromitzer
Copy link

You should open a new ticket or ask in discord.
If you ask in an issue which an different topic, nobody will find the question to help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants