我是靠谱客的博主 背后草丛,这篇文章主要介绍Carla实现强化学习(1)安装所需模块carla创建一个汽车并添加摄像头展示摄像头获取的画面图片的reshape报错,现在分享给大家,希望可以做个参考。

Carla实现强化学习(1

  • 安装所需模块
  • carla创建一个汽车并添加摄像头展示摄像头获取的画面
  • 图片的reshape报错

安装所需模块

首先下载carla
链接: https://pan.baidu.com/s/1JTfm93EjYNXBgeUrN6Z8lQ 提取码: qxf4
注意:python的版本使用3.7 不然的话会报错
安装tensorflow

复制代码
1
2
3
pip install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple pip install tensorflow-gpu==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

carla创建一个汽车并添加摄像头展示摄像头获取的画面

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import glob import os import sys import random import time import numpy as np import cv2 try: sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % ( sys.version_info.major, sys.version_info.minor, 'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0]) except IndexError: pass import carla IMG_WIDTH=600 IMG_HEIGHT=480 def process_img(image): i=np.array(image.raw_data) print(i.shape) i2=i.reshape((IMG_HEIGHT,IMG_WIDTH,4)) i3=i2[:,:,:3] #所有的高度和rgb,不要alpha通道,快速获取RGB #print(dir(image)) cv2.imshow('',i3) cv2.waitKey(1) return i3/255.0 actor_list=[] try: ##生成一个车辆 client=carla.Client(host='127.0.0.1', port=2000) #连接主机 client.set_timeout(2.0) world=client.get_world() blueprint_library=world.get_blueprint_library() bp=blueprint_library.filter('model3')[0]#获取车辆 print(bp) spaw_point=random.choice(world.get_map().get_spawn_points())#在随机点生成车辆 ,随机点 vehicle=world.spawn_actor(bp,spaw_point)#随机点生成车辆 #vehicle.set_autopilot(True) #基于规则的行驶 vehicle.apply_control(carla.VehicleControl(throttle=1.0,steer=0.0)) actor_list.append(vehicle) ##在车辆上方安装传感器,以满足后面的碰撞检测 cam_bp=blueprint_library.find('sensor.camera.rgb') cam_bp.set_attribute('image_size_x',f"{IMG_WIDTH}") cam_bp.set_attribute('image_size_x', f"{IMG_HEIGHT}") cam_bp.set_attribute('fov','110') spawn_point=carla.Transform(carla.Location(x=2.5,z=0.7))#将摄像机的位置进行设置 sensor=world.spawn_actor(cam_bp,spawn_point,attach_to=vehicle) actor_list.append(sensor) sensor.listen(lambda data:process_img(data)) time.sleep(10) finally: for actor in actor_list: actor.destroy() actor.destroy() print('All cleaned up!')

图片的reshape报错

ValueError: cannot reshape array of size 149184 into shape (28,28,1)
由于图片的w,h,c相乘不等于149184所导致的。也就是说这张图片的shape不能是(28,28,1)。

最后

以上就是背后草丛最近收集整理的关于Carla实现强化学习(1)安装所需模块carla创建一个汽车并添加摄像头展示摄像头获取的画面图片的reshape报错的全部内容,更多相关Carla实现强化学习(1)安装所需模块carla创建一个汽车并添加摄像头展示摄像头获取内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部