diff --git a/template/agent_prompt.py b/template/agent_prompt.py index de78f0d..c9c8f93 100644 --- a/template/agent_prompt.py +++ b/template/agent_prompt.py @@ -85,6 +85,8 @@ Tips for you to finish task in the most efficient way: 4. Getting entities nearby do not always effective. You have only limited sensor range. Using /targets API to get targets and /obstacles API to get obstacles is more effective. 5. If battery is below 30, find the nerest waypoint, go there and land, then charge to 100. 6. Reaching to a higher latitude can help you see targets, but do not exceed the drone's limit. +7. We put your answer to langchain, so if you want to return {{ or }}, return double of the characters. +8. Cannot move from current status: DroneStatus.IDLE means you need to take off first then move. Begin! diff --git a/template/maps/golden_gate_bridge.png b/template/maps/golden_gate_bridge.png new file mode 100644 index 0000000..efcdad9 Binary files /dev/null and b/template/maps/golden_gate_bridge.png differ diff --git a/template/maps/process.py b/template/maps/process.py new file mode 100644 index 0000000..2dea846 --- /dev/null +++ b/template/maps/process.py @@ -0,0 +1,76 @@ +import cv2 +import numpy as np + +def extract_green_polygons(image_path): + # 1. 读取图片 + img = cv2.imread(image_path) + if img is None: + print("无法读取图片") + return [] + + # 获取图片尺寸 + height, width = img.shape[:2] + + # 定义目标坐标系范围 + target_w, target_h = 1465, 715 + + # 2. 转换颜色空间到 HSV 以便提取绿色 + hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) + + # 定义绿色的 HSV 范围 + lower_green = np.array([35, 20, 200]) + upper_green = np.array([85, 255, 255]) + + # 3. 创建掩膜 (Mask) + mask = cv2.inRange(hsv, lower_green, upper_green) + + # 4. 图像形态学处理 + kernel = np.ones((3,3), np.uint8) + mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) + mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) + + # 5. 查找轮廓 + contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + + polygons = [] + + for i, contour in enumerate(contours): + # 过滤掉太小的区域 + if cv2.contourArea(contour) < 100: + continue + + points = [] + # 6. 坐标转换 + for point in contour: + px, py = point[0] + + # 【修改点1】:这里显式转换成 float(),去除 numpy 类型包裹 + # X 轴转换: 线性缩放 + new_x = float((px / width) * target_w) + + # Y 轴转换: 图像坐标系 -> 笛卡尔坐标系 + new_y = float(((height - py) / height) * target_h) + + # 保留两位小数 + points.append((round(new_x, 2), round(new_y, 2))) + + polygons.append({ + "id": i, + "vertex_count": len(points), + "coordinates": points + }) + + return polygons + +# --- 使用说明 --- +results = extract_green_polygons("golden_gate_bridge.png") + +if not results: + print("未找到多边形或图片读取失败") +else: + for poly in results: + print(f"--- 多边形 ID: {poly['id']} (顶点数: {poly['vertex_count']}) ---") + # 【修改点2】:遍历坐标列表,每行输出两个数字 (x y) + for x, y in poly['coordinates']: + print(f"{x}, {y}") + print("") # 每个多边形之间空一行,方便区分 \ No newline at end of file