简体   繁体   English

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

[英]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.

相关问题 在我的Python CGI脚本中,如何将用户通过表单输入的数据通过POST请求上传到磁盘上的文件保存到磁盘上? - In my Python CGI script, how do I save to disk a file uploaded via POST request of data entered by the user in a form? 如何自动将我抓取的数据保存到我的数据库 - How do I automatically save my scraped data to my Database 如何不覆盖我的保存数据? (python中的泡菜) - How do I not overwrite my save data? (pickle in python) 如何解析 JSON 数据并将其保存在我的 postgresql 表中? - How do I parse JSON data and save it my postgresql table? 如何正确地将数据保存在磁盘缓存中? - How to save data in disk cache properly? 如何在Python中以UTF-8编码将数据写入磁盘? - How do I write data to disk in UTF-8 encoding in Python? 如何使用pickle将数据保存到磁盘? - How to use pickle to save data to disk? Python如何与Carla模拟器建立数据通信? - How to establish data communication between Python and the Carla simulator? 如何在 Python 中将 GeoDataFrame 保存到磁盘? - How can I save a GeoDataFrame to disk in Python? 如何将网页保存到磁盘以供以后使用 splinter 库抓取? - How do I save a webpage to the disk for later scraping using splinter library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM