Append file extension if missing when saving sensor data
This commit is contained in:
parent
82d156cda4
commit
5cd21fc22b
|
@ -32,6 +32,10 @@ Point = namedtuple('Point', 'x y z color')
|
|||
Point.__new__.__defaults__ = (0.0, 0.0, 0.0, None)
|
||||
|
||||
|
||||
def _append_extension(filename, ext):
|
||||
return filename if filename.lower().endswith(ext.lower()) else filename + ext
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# -- Sensor --------------------------------------------------------------------
|
||||
# ==============================================================================
|
||||
|
@ -166,6 +170,8 @@ class Image(SensorData):
|
|||
|
||||
def save_to_disk(self, filename):
|
||||
"""Save this image to disk (requires PIL installed)."""
|
||||
filename = _append_extension(filename, '.png')
|
||||
|
||||
try:
|
||||
from PIL import Image as PImage
|
||||
except ImportError:
|
||||
|
@ -227,6 +233,7 @@ class PointCloud(SensorData):
|
|||
|
||||
def save_to_disk(self, filename):
|
||||
"""Save this point-cloud to disk as PLY format."""
|
||||
filename = _append_extension(filename, '.ply')
|
||||
|
||||
def construct_ply_header():
|
||||
"""Generates a PLY header given a total number of 3D points and
|
||||
|
|
|
@ -117,11 +117,8 @@ def run_carla_client(args):
|
|||
# Save the images to disk if requested.
|
||||
if args.save_images_to_disk:
|
||||
for name, measurement in sensor_data.items():
|
||||
if isinstance(measurement, LidarMeasurement):
|
||||
filename = args.lidar_filename_format
|
||||
else:
|
||||
filename = args.image_filename_format
|
||||
measurement.save_to_disk(filename.format(episode, name, frame))
|
||||
filename = args.out_filename_format.format(episode, name, frame)
|
||||
measurement.save_to_disk(filename)
|
||||
|
||||
# We can access the encoded data of a given image as numpy
|
||||
# array using its "data" property. For instance, to get the
|
||||
|
@ -223,8 +220,7 @@ def main():
|
|||
|
||||
logging.info('listening to server %s:%s', args.host, args.port)
|
||||
|
||||
args.image_filename_format = '_out/episode_{:0>4d}/{:s}/{:0>6d}.png'
|
||||
args.lidar_filename_format = '_out/episode_{:0>4d}/{:s}/{:0>6d}.ply'
|
||||
args.out_filename_format = '_out/episode_{:0>4d}/{:s}/{:0>6d}'
|
||||
|
||||
while True:
|
||||
try:
|
||||
|
|
|
@ -19,8 +19,8 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|||
|
||||
import carla
|
||||
|
||||
from carla import sensor
|
||||
from carla.client import CarlaClient
|
||||
from carla.sensor import Camera, Image
|
||||
from carla.settings import CarlaSettings
|
||||
from carla.tcp import TCPClient
|
||||
from carla.util import make_connection
|
||||
|
@ -31,17 +31,19 @@ import console
|
|||
def run_carla_client(args):
|
||||
with make_connection(CarlaClient, args.host, args.port, timeout=15) as client:
|
||||
logging.info('CarlaClient connected')
|
||||
filename = '_images/episode_{:0>3d}/image_{:0>5d}.png'
|
||||
filename = '_out/test_episode_{:0>4d}/{:s}/{:0>6d}'
|
||||
frames_per_episode = 300
|
||||
episode = 0
|
||||
while True:
|
||||
episode += 1
|
||||
settings = CarlaSettings()
|
||||
settings.set(SendNonPlayerAgentsInfo=True,SynchronousMode=args.synchronous)
|
||||
settings.set(SendNonPlayerAgentsInfo=True, SynchronousMode=args.synchronous)
|
||||
settings.randomize_seeds()
|
||||
camera = Camera('DefaultCamera')
|
||||
camera = sensor.Camera('DefaultCamera')
|
||||
camera.set_image_size(300, 200) # Do not change this, hard-coded in test.
|
||||
settings.add_sensor(camera)
|
||||
lidar = sensor.Lidar('DefaultLidar')
|
||||
settings.add_sensor(lidar)
|
||||
|
||||
logging.debug('sending CarlaSettings:\n%s', settings)
|
||||
logging.info('new episode requested')
|
||||
|
@ -64,14 +66,15 @@ def run_carla_client(args):
|
|||
for frame in range(0, frames_per_episode):
|
||||
logging.debug('reading measurements...')
|
||||
measurements, sensor_data = client.read_data()
|
||||
images = [x for x in sensor_data.values() if isinstance(x, Image)]
|
||||
images = [x for x in sensor_data.values() if isinstance(x, sensor.Image)]
|
||||
|
||||
logging.debug('received data of %d agents', len(measurements.non_player_agents))
|
||||
if len(images) > 0:
|
||||
assert (images[0].width, images[0].height) == (camera.ImageSizeX, camera.ImageSizeY)
|
||||
|
||||
if args.images_to_disk:
|
||||
images[0].save_to_disk(filename.format(episode, frame))
|
||||
for name, data in sensor_data.items():
|
||||
data.save_to_disk(filename.format(episode, name, frame))
|
||||
|
||||
logging.debug('sending control...')
|
||||
control = measurements.player_measurements.autopilot_control
|
||||
|
|
Loading…
Reference in New Issue