完善AEM
This commit is contained in:
parent
504aeb40fe
commit
938d2a5a6e
|
@ -370,7 +370,7 @@ def get_id_object_pixels(id, scene):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_obstacle_point(db, scene, cur_obstacle_world_points, map_ratio):
|
def get_obstacle_point(plt, db, scene, cur_obstacle_world_points, map_ratio):
|
||||||
cur_obstacle_pixel_points = []
|
cur_obstacle_pixel_points = []
|
||||||
object_pixels = {}
|
object_pixels = {}
|
||||||
colors = [
|
colors = [
|
||||||
|
@ -439,13 +439,16 @@ def get_obstacle_point(db, scene, cur_obstacle_world_points, map_ratio):
|
||||||
world_point = transform_co(img_data_depth, pixel[0], pixel[1], d_depth[pixel[0]][pixel[1]][0], scene)
|
world_point = transform_co(img_data_depth, pixel[0], pixel[1], d_depth[pixel[0]][pixel[1]][0], scene)
|
||||||
cur_obstacle_world_points.append([world_point[0], world_point[1]])
|
cur_obstacle_world_points.append([world_point[0], world_point[1]])
|
||||||
# print(f"{pixel}:{[world_point[0], world_point[1]]}")
|
# print(f"{pixel}:{[world_point[0], world_point[1]]}")
|
||||||
|
plt.subplot(2, 1, 1)
|
||||||
plt.imshow(d_color, cmap="gray" if "depth" in im_depth.name.lower() else None)
|
plt.imshow(d_color, cmap="gray" if "depth" in im_depth.name.lower() else None)
|
||||||
|
plt.axis('off')
|
||||||
|
plt.title("目标检测")
|
||||||
|
# plt.tight_layout()
|
||||||
|
|
||||||
for key, value in object_pixels.items():
|
for key, value in object_pixels.items():
|
||||||
if key == 101 or key == 0:
|
if key == 0:
|
||||||
continue
|
continue
|
||||||
if key in [91, 84]:
|
if key in [91, 84, 96, 87, 102, 106, 120, 85,113, 101, 83]:
|
||||||
X = np.array(value)
|
X = np.array(value)
|
||||||
db.fit(X)
|
db.fit(X)
|
||||||
labels = db.labels_
|
labels = db.labels_
|
||||||
|
@ -487,7 +490,8 @@ def get_obstacle_point(db, scene, cur_obstacle_world_points, map_ratio):
|
||||||
|
|
||||||
# 将矩形框添加到图像中
|
# 将矩形框添加到图像中
|
||||||
# plt.gca().add_patch(rect)
|
# plt.gca().add_patch(rect)
|
||||||
plt.show()
|
|
||||||
|
# plt.show()
|
||||||
return cur_obstacle_world_points
|
return cur_obstacle_world_points
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -751,7 +751,7 @@ class Scene:
|
||||||
scene = stub.Do(action)
|
scene = stub.Do(action)
|
||||||
print(scene.info)
|
print(scene.info)
|
||||||
|
|
||||||
def navigation_move(self, cur_objs, objs_name_set, cur_obstacle_world_points, v_list, map_ratio, db, scene_id=0, map_id=11):
|
def navigation_move(self, plt, cur_objs, objs_name_set, cur_obstacle_world_points, v_list, map_ratio, db, scene_id=0, map_id=11):
|
||||||
print('------------------navigation_move----------------------')
|
print('------------------navigation_move----------------------')
|
||||||
scene = stub.Observe(GrabSim_pb2.SceneID(value=scene_id))
|
scene = stub.Observe(GrabSim_pb2.SceneID(value=scene_id))
|
||||||
walk_value = [scene.location.X, scene.location.Y]
|
walk_value = [scene.location.X, scene.location.Y]
|
||||||
|
@ -767,7 +767,7 @@ class Scene:
|
||||||
cur_objs, objs_name_set = camera.get_semantic_map(GrabSim_pb2.CameraName.Head_Segment, cur_objs,
|
cur_objs, objs_name_set = camera.get_semantic_map(GrabSim_pb2.CameraName.Head_Segment, cur_objs,
|
||||||
objs_name_set)
|
objs_name_set)
|
||||||
|
|
||||||
cur_obstacle_world_points = camera.get_obstacle_point(db, scene, cur_obstacle_world_points,map_ratio)
|
cur_obstacle_world_points = camera.get_obstacle_point(plt, db, scene, cur_obstacle_world_points,map_ratio)
|
||||||
|
|
||||||
|
|
||||||
# if scene.info == "Unreachable":
|
# if scene.info == "Unreachable":
|
||||||
|
@ -789,7 +789,7 @@ class Scene:
|
||||||
cur_objs, objs_name_set = camera.get_semantic_map(GrabSim_pb2.CameraName.Head_Segment, cur_objs,
|
cur_objs, objs_name_set = camera.get_semantic_map(GrabSim_pb2.CameraName.Head_Segment, cur_objs,
|
||||||
objs_name_set)
|
objs_name_set)
|
||||||
|
|
||||||
cur_obstacle_world_points = camera.get_obstacle_point(db, scene, cur_obstacle_world_points, map_ratio)
|
cur_obstacle_world_points = camera.get_obstacle_point(plt, db, scene, cur_obstacle_world_points, map_ratio)
|
||||||
|
|
||||||
|
|
||||||
# if scene.info == "Unreachable":
|
# if scene.info == "Unreachable":
|
||||||
|
|
|
@ -11,6 +11,8 @@ import pickle
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
|
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
|
||||||
|
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
|
||||||
from sklearn.cluster import DBSCAN
|
from sklearn.cluster import DBSCAN
|
||||||
|
|
||||||
from robowaiter.scene.scene import Scene
|
from robowaiter.scene.scene import Scene
|
||||||
|
@ -51,11 +53,13 @@ class SceneAEM(Scene):
|
||||||
# navigation_test(i,map_id)
|
# navigation_test(i,map_id)
|
||||||
map_map = np.zeros((math.ceil(950 / map_ratio), math.ceil(1850 / map_ratio)))
|
map_map = np.zeros((math.ceil(950 / map_ratio), math.ceil(1850 / map_ratio)))
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
fig = plt.figure()
|
||||||
goal = self.explore(map, 120) # cur_pos 指的是当前机器人的位置,场景中应该也有接口可以获取
|
goal = self.explore(map, 120) # cur_pos 指的是当前机器人的位置,场景中应该也有接口可以获取
|
||||||
if goal is None:
|
if goal is None:
|
||||||
break
|
break
|
||||||
cur_objs, objs_name_set, cur_obstacle_world_points= self.navigation_move(cur_objs, objs_name_set, cur_obstacle_world_points, [[goal[0], goal[1]]], map_ratio, db,0, 11)
|
cur_objs, objs_name_set, cur_obstacle_world_points= self.navigation_move(plt, cur_objs, objs_name_set, cur_obstacle_world_points, [[goal[0], goal[1]]], map_ratio, db,0, 11)
|
||||||
|
|
||||||
for point in cur_obstacle_world_points:
|
for point in cur_obstacle_world_points:
|
||||||
if point[0] < -350 or point[0] > 600 or point[1] < -400 or point[1] > 1450:
|
if point[0] < -350 or point[0] > 600 or point[1] < -400 or point[1] > 1450:
|
||||||
|
@ -67,33 +71,46 @@ class SceneAEM(Scene):
|
||||||
# -350 / map_ratio, 600 / map_ratio))
|
# -350 / map_ratio, 600 / map_ratio))
|
||||||
|
|
||||||
# 使用imshow函数绘制图像,其中cmap参数设置颜色映射
|
# 使用imshow函数绘制图像,其中cmap参数设置颜色映射
|
||||||
|
|
||||||
|
plt.subplot(2, 1, 2) # 这里的2,1表示总共2行,1列,2表示这个位置是第2个子图
|
||||||
plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower',
|
plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower',
|
||||||
extent=(-400 / map_ratio, 1450 / map_ratio,
|
extent=(-400 / map_ratio, 1450 / map_ratio,
|
||||||
-350 / map_ratio, 600 / map_ratio))
|
-350 / map_ratio, 600 / map_ratio))
|
||||||
# plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower')
|
# plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower')
|
||||||
# plt.axis('off')
|
# plt.axis('off')
|
||||||
|
plt.title("地图构建过程")
|
||||||
plt.show()
|
plt.show()
|
||||||
|
print("------------当前检测到的物品信息--------------")
|
||||||
|
print(cur_objs)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print("------------物品信息--------------")
|
|
||||||
print(cur_objs)
|
|
||||||
|
|
||||||
for i in range(len(cur_objs)):
|
for i in range(len(cur_objs)):
|
||||||
obj_json_data.append({"id":f"{i}", "name":f"{cur_objs[i].name}", "location":f"{cur_objs[i].location}", "height":f"{cur_objs[i].location.Z * 2}"})
|
if cur_objs[i].name == "Desk" or cur_objs[i].name == "Chair":
|
||||||
|
obj_json_data.append({"id":f"{i}", "name":f"{cur_objs[i].name}", "location":f"{cur_objs[i].location}", "height":f"{cur_objs[i].location.Z * 2}"})
|
||||||
|
|
||||||
|
else:
|
||||||
|
obj_json_data.append(
|
||||||
|
{"id": f"{i}", "name": f"{cur_objs[i].name}", "location": f"{cur_objs[i].location}",
|
||||||
|
"height": f"{cur_objs[i].location.Z}"})
|
||||||
|
|
||||||
with open('../../proto/objs.json', 'w') as file:
|
with open('../../proto/objs.json', 'w') as file:
|
||||||
json.dump(obj_json_data, file)
|
json.dump(obj_json_data, file)
|
||||||
|
|
||||||
# for i in range(-350, 600):
|
# for i in range(-350, 600):
|
||||||
# for j in range(-400, 1450):
|
# for j in range(-400, 1450):
|
||||||
# i = (math.floor((i + 350) / map_ratio))
|
# i = (math.floor((i + 350) / map_ratio))
|
||||||
# j = (math.floor((j + 400) / map_ratio))
|
# j = (math.floor((j + 400) / map_ratio))
|
||||||
# if (i, j) not in visited_obstacle:
|
# if (i, j) not in visited_obstacle:
|
||||||
# map_map[i][j] = 1
|
# map_map[i][j] = 1
|
||||||
plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower',
|
# plt.imshow(map_map, cmap='binary', alpha=0.5, origin='lower',
|
||||||
extent=(-400 / map_ratio, 1450 / map_ratio,
|
# extent=(-400 / map_ratio, 1450 / map_ratio,
|
||||||
-350 / map_ratio, 600 / map_ratio))
|
# -350 / map_ratio, 600 / map_ratio))
|
||||||
# plt.axis('off')
|
# plt.axis('off')
|
||||||
plt.show()
|
# plt.show()
|
||||||
print("已绘制完成地图!!!")
|
print("已绘制完成地图!!!")
|
||||||
|
print("------------检测到的所有物品信息--------------")
|
||||||
|
print(obj_json_data)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue