如何保存Carla的相机数据到我的磁盘?



我正在使用卡拉模拟器,并希望为语义分割制作自己的数据集。但问题是我不能把它们保存在我的电脑上。我有相机和所有东西,但我不能把它存到磁盘上。我正在使用Jupyter笔记本,内核自己关闭了。最后,我想要我相机的png数据。问题在最后(图片)。save_to_disk)

import glob
import os
import sys
import random
from turtle import width
import carla
from matplotlib import image
import tensorflow as tf
import cv2
import numpy as np
import time
import argparse
import imutils
print("")
# Laden von Carla,Library,Map, erstellen des Spectators
client = carla.Client('localhost', 2000)
client.set_timeout(500.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
spectator = world.get_spectator()
bp_lib = world.get_blueprint_library()  
spawn_points = world.get_map().get_spawn_points() 

```
#Laden von Carla,Library,Map, erstellen des Spectators
client = carla.Client('localhost', 2000)
client.set_timeout(500.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
spawnpoints = world.get_map().get_spawn_points()
spectator = world.get_spectator()
#Nun Einstellungen zum Fahrzeug
vehicle_blueprint = blueprint_library.find('vehicle.audi.etron')
#Fahrzeug wird an einem zufälligen Spawnpunkt gespawnt
vehicle = world.try_spawn_actor(vehicle_blueprint,random.choice(spawnpoints))
transform = carla.Transform(vehicle.get_transform().transform(carla.Location(x=2,z=0.5)),vehicle.get_transform().rotation)
spectator.set_transform(transform)
#Kamera
camera_blueprint = blueprint_library.find('sensor.camera.rgb')
camera_transform = carla.Transform(carla.Location(z=2,x=0.5))
camera = world.spawn_actor(camera_blueprint,camera_transform,attach_to=vehicle)
def camera_callback(image,data):
data['image'] = np.reshape(np.copy(image.raw_data), (image.height, image.width, 4))
image_width = camera_blueprint.get_attribute("image_size_x").as_int()
image_height = camera_blueprint.get_attribute("image_size_y").as_int()
camera_data = {'image': np.zeros((image_height,image_width, 4))}
camera.listen(lambda image: camera_callback(image, camera_data))

#Anzeigen des Bildes
cv2.namedWindow('Camera', cv2.WINDOW_AUTOSIZE)
cv2.imshow('Camera', camera_data['image'])
cv2.waitKey(1)
while True:
img = cv2.imshow('Camera', camera_data['image'])
vehicle.set_autopilot(True)
camera.listen(lambda image: image.save_to_disk(r"C:UsersJoshiDesktopCARLA_0.9.13WindowsNoEditorPythonAPIexamplesout",color_converter=None))
if cv2.waitKey(1) == ord('p'):
client.reload_world()
break
cv2.destroyAllWindows()
```
```
`

为什么不将图像保存在camera_callback内部呢?

,

def camera_callback(image, data):
capture = np.reshape(np.copy(image.raw_data), (image.height, image.width, 4))
data['image'] = capture
cv2.imwrite(f"{image.frame}.png", capture)

或:

def camera_callback(image, data):
data['image'] = np.reshape(np.copy(image.raw_data), (image.height, image.width, 4))
image.save_to_disk(f"{image.frame}.png")

相关内容

  • 没有找到相关文章