Camera.listen()在Carla中未能正确输出图像。

huangapple go评论63阅读模式
英文:

Camera.listen() not giving proper image output in Carla

问题

camera.listen(lambda image: image.save_to_disk('out/%06d.png' % image.frame)) 这一行是问题所在。根据Carla文档,它应该返回单独的图像帧。但实际上,它返回了多个帧组合在一张图像中。你尝试导入了Pillow库的Image模块并使用Image的.save方法来保存图片,但没有成功。你还尝试创建一个保存函数,也没有成功。

英文:

The listen method of the Carla sensor has the ability to take images. When I attach an RBG sensors to my vehicle, instead of returning a clear image every frame, it returns what I think (I am not sure if that is what the issue is) a bunch of frames grouped together into one image.

Below is my code:

import carla
import random
import time
from PIL import Image
Image


# Connect to the client and retrieve the world object
client = carla.Client('localhost', 2000)
world = client.get_world()
spectator = world.get_spectator()
getLocation = spectator.get_transform()

# Set the spectator with an empty transform
spectator.set_transform(carla.Transform())

# Get the blueprint library and filter for the vehicle blueprints
vehicle_blueprints = world.get_blueprint_library().filter('*vehicle*')

# Get the map's spawn points
spawn_points = world.get_map().get_spawn_points()

# Spawn 50 vehicles randomly distributed throughout the map
for _ in range(50):
    world.try_spawn_actor(random.choice(vehicle_blueprints), random.choice(spawn_points))

ego_vehicle = world.spawn_actor(random.choice(vehicle_blueprints), random.choice(spawn_points))

# Create a transform to place the camera on top of the vehicle
camera_init_trans = carla.Transform(carla.Location(z=4))

# We create the camera through a blueprint that defines its properties
camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')

# We spawn the camera and attach it to our ego vehicle
camera = world.spawn_actor(camera_bp, camera_init_trans, attach_to=ego_vehicle)

# Register the callback function to receive the image data
camera.listen(lambda image: image.save_to_disk('out/%06d.png' % image.frame))

EgoLocation = ego_vehicle.get_location()

for vehicle in world.get_actors().filter('*vehicle*'):
    vehicle.set_autopilot(True)

spectator.set_transform(carla.Transform(EgoLocation))
time.sleep(10)
camera.stop()

This line is the problem:

# Register the callback function to receive the image data
camera.listen(lambda image: image.save_to_disk('out/%06d.png' % image.frame))

What it should be returning according to Carla documentation: Camera.listen()在Carla中未能正确输出图像。

What it is actually returning:
Camera.listen()在Carla中未能正确输出图像。

and its not just one of those its returning. Its multiple:
Camera.listen()在Carla中未能正确输出图像。

I tried importing Image from pillow and using Image's .save method to try and save the photo that way which didn't work. I also tried to make a save function which didn't work.

答案1

得分: 0

Add this code:

self.IM_WIDTH = 640
self.IM_HEIGHT = 480
camera_bp.set_attribute('image_size_x', str(self.IM_WIDTH))
camera_bp.set_attribute('image_size_y', str(self.IM_HEIGHT))

After:

camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')
英文:

Add this code

self.IM_WIDTH = 640
self.IM_HEIGHT = 480
camera_bp.set_attribute('image_size_x', str(self.IM_WIDTH))
camera_bp.set_attribute('image_size_y', str(self.IM_HEIGHT))

After

camera_bp = world.get_blueprint_library().find('sensor.camera.rgb')

huangapple
  • 本文由 发表于 2023年6月12日 22:50:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定