地图实现根据行列号和层级重新计算bbox边界范围(投影坐标转球面坐标)

具体的实现代码如下:

const EARTH_RADIUS = 6378137;
const TILE_SIZE = 256;
const origin = [-20037508.34, 20037508.34];

function calculateTileBounds(x, y, z) {
    const d = 2 * EARTH_RADIUS * Math.PI;
    const size = TILE_SIZE * (d / (TILE_SIZE * Math.pow(2, z)));

    const minX = origin[0] + x * size;
    const maxX = origin[0] + (x + 1) * size;
    const minY = origin[1] - (y + 1) * size;
    const maxY = origin[1] - y * size;

    return { minX, minY, maxX, maxY };
}

function mercatorToWGS84(x, y) {
    const lon = (x / EARTH_RADIUS) * (180 / Math.PI);
    const lat = (Math.atan(Math.exp(y / EARTH_RADIUS)) * 360 / Math.PI) - 90;
    return [lon, lat];
}

function generateWMSUrl(x, y, z) {
    const { minX, minY, maxX, maxY } = calculateTileBounds(x, y, z);
    const xy0 = mercatorToWGS84(minX, minY);
    const xy1 = mercatorToWGS84(maxX, maxY);

    return `http://url/wms?BBOX=${xy0[0]
  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Yolo格式中,每个目标都用一个包含其类别、中心点、宽度和高度的矩形来表示。在COCO格式中,每个目标都用一个包含其所有像素的掩码来表示。因此,将Yolo格式换为COCO格式需要通过计算目标的像素掩码来实现。 以下是将Yolo格式换为COCO格式的Python代码示例: ``` import numpy as np import cv2 # Yolo格式坐标换为COCO格式坐标 def yolo2coco(bbox, img_width, img_height): x, y, w, h = bbox left = int((x - w / 2) * img_width) right = int((x + w / 2) * img_width) top = int((y - h / 2) * img_height) bottom = int((y + h / 2) * img_height) return [left, top, right, bottom] # COCO格式坐标换为Yolo格式坐标 def coco2yolo(bbox, img_width, img_height): left, top, right, bottom = bbox x = (left + right) / 2 / img_width y = (top + bottom) / 2 / img_height w = (right - left) / img_width h = (bottom - top) / img_height return [x, y, w, h] # 读取Yolo格式标注文件 def read_yolo_annotation(annotation_file): with open(annotation_file, 'r') as f: lines = f.readlines() annotations = [] for line in lines: line = line.strip() if not line: continue parts = line.split() class_id = int(parts[0]) bbox = [float(x) for x in parts[1:]] annotations.append((class_id, bbox)) return annotations # 将Yolo格式标注换为COCO格式标注 def yolo2coco_annotation(yolo_annotation, img_width, img_height): coco_annotation = [] for class_id, bbox in yolo_annotation: coco_bbox = yolo2coco(bbox, img_width, img_height) mask = np.zeros((img_height, img_width), dtype=np.uint8) cv2.rectangle(mask, (coco_bbox[0], coco_bbox[1]), (coco_bbox[2], coco_bbox[3]), 1, thickness=-1) coco_annotation.append({'category_id': class_id, 'bbox': coco_bbox, 'segmentation': mask}) return coco_annotation # 将COCO格式标注换为Yolo格式标注 def coco2yolo_annotation(coco_annotation, img_width, img_height): yolo_annotation = [] for ann in coco_annotation: class_id = ann['category_id'] coco_bbox = ann['bbox'] yolo_bbox = coco2yolo(coco_bbox, img_width, img_height) yolo_annotation.append((class_id, yolo_bbox)) return yolo_annotation ``` 其中,`yolo2coco`函数将Yolo格式的坐标换为COCO格式的坐标,`coco2yolo`函数将COCO格式的坐标换为Yolo格式的坐标。`read_yolo_annotation`函数从Yolo格式的标注文件中读取标注信息,`yolo2coco_annotation`函数将Yolo格式的标注换为COCO格式的标注,`coco2yolo_annotation`函数将COCO格式的标注换为Yolo格式的标注。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值