[英]How do I save the camera Data of Carla to my disk?
I am working with the Carla Simulator and want to make my own Dataset for semantic segmentation.我正在使用 Carla 模拟器,并希望为语义分割制作我自己的数据集。 But the problem is I can not save them on my computer.
但问题是我无法将它们保存在我的电脑上。 I got a camera and everything but I can not save it to the disk.
我有一台相机和所有东西,但我无法将它保存到磁盘上。 I am working with Jupyter Notebooks and the kernel just shut down himself.
我正在使用 Jupyter Notebooks,而 kernel 刚刚关闭了自己。 In the end, I want to have png data of my camera.
最后,我想要我的相机的 png 数据。 The problem is at the end ( image.save_to_disk )
问题在最后(image.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:\Users\Joshi\Desktop\CARLA_0.9.13\WindowsNoEditor\PythonAPI\examples\out",color_converter=None))
if cv2.waitKey(1) == ord('p'):
client.reload_world()
break
cv2.destroyAllWindows()
```
```
`
Why don't you save the image inside camera_callback
itself?为什么不将图像保存在
camera_callback
本身中?
Eg:例如:
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)
Or:或者:
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.