geohash bbox 生成四个顶点坐标

编码实现-硬扣代码

_all__ = ['encode', 'decode', 'bbox', 'neighbors']
_base32 = '0123456789bcdefghjkmnpqrstuvwxyz'
# 10进制和32进制转换,32进制去掉了ailo
_decode_map = {
   }
_encode_map = {
   }
for i in range(len(_base32)):
    _decode_map[_base32[i]] = i
    _encode_map[i]=_base32[i]


def bbox(geohash):
    lat_range, lon_range = 
### 旋转目标检测中的四个顶点处理 在旋转目标检测任务中,对于四个顶点的处理通常采用有序四边形定义法。这种方法不直接表示角度值,而是通过记录旋转矩形框上四个角的具体坐标来描述物体的位置和姿态[^3]。 具体来说,在标注数据集时,每个对象会被标记为其边界框的四个顶点坐标(x1, y1), (x2, y2), (x3, y3), 和 (x4, y4),这些点按照顺时针方向排列形成一个封闭多边形。为了确保模型能够正确理解并预测这种类型的边界框,在训练过程中需要特别注意输入特征的设计以及损失函数的选择。 #### 数据预处理阶段 当准备用于训练的数据时,应该将原始图像及其对应的标签转换成适合网络接收的形式: - 对于每一张图片,提取其中所有感兴趣的对象,并获取它们各自的四个顶点位置; - 将这八个数值(即两个维度上的四个坐标)作为回归的目标向量传递给神经网络; ```python import numpy as np def prepare_data(image, labels): # 假设labels是一个列表,里面包含了多个字典, # 每个字典代表一个物体的信息{'class': ..., 'points': [(x1,y1),(x2,y2)...]} processed_labels = [] for obj in labels: class_name = obj['class'] points = np.array(obj['points']) # 计算中心点和其他属性... center_x = sum([p[0] for p in points]) / 4.0 center_y = sum([p[1] for p in points]) / 4.0 width = max(abs(points[i][0]-points[(i+1)%4][0]) for i in range(4)) height = max(abs(points[i][1]-points[(i+1)%4][1]) for i in range(4)) angle = ... # 可选计算角度信息 processed_label = { "center": [center_x, center_y], "size":[width,height], "angle":angle, "vertices": list(map(tuple,map(int,points))) } processed_labels.append(processed_label) return image, processed_labels ``` #### 模型架构调整 为了让深度学习框架更好地适应此类任务需,可能还需要对现有算法做出一些改动或优化: - 修改最后一层输出结构以支持更多参数的学习; - 设计专门针对OBB( Oriented Bounding Box)形式的损失函数; 例如,在基于YOLO系列改进后的版本Rotation-YOLOv5 中,就引入了新的机制来提高对倾斜物体识别的效果[^1]. #### 后处理步骤 完成前向传播之后得到的结果往往不是最终想要的形式,因此还需经过一系列操作才能获得理想的输出: - 解码过程会把网络给出的概率分布转化为具体的几何形状; - 非极大抑制(NMS)可以去除冗余检测结果只保留最有可能的那个选项; ```python from scipy.spatial import distance_matrix def nms_rotated_boxes(detections, threshold=0.7): """ detections: List of dictionaries containing detection results. Each dictionary should have keys ['score', 'bbox'] where bbox is a tuple with eight elements representing four vertices coordinates. Returns filtered detections after applying NMS on rotated bounding boxes. """ if not detections: return [] scores = [d['score'] for d in detections] indices_sorted_by_score = sorted(range(len(scores)), key=lambda k: -scores[k]) keep_indices = [] while len(indices_sorted_by_score)>0: idx_max = indices_sorted_by_score.pop(0) keep_indices.append(idx_max) remaining_bboxes = [detections[idx]['bbox'] for idx in indices_sorted_by_score] distances_between_centers = distance_matrix( [[sum(bbox[i::2])/4 for i in range(2)] for bbox in remaining_bboxes], [[sum(detections[idx_max]['bbox'][i::2])/4 for i in range(2)]] ).flatten() angles_diffs = [ min(abs(a-b), abs((a%np.pi*2)-(b%np.pi*2))) for a,b in zip( map(lambda b:(np.arctan2(b[3]-b[1],b[2]-b[0])+np.pi/2)%np.pi,detections), itertools.repeat(np.arctan2(*reversed([ sum([(y-x)[j]for j in range(i,i+8,2)])//4 for i,x,y in zip(itertools.count(),*[iter(detections[idx_max]['bbox'])]*2)] ))+(np.pi/2))%(np.pi),len(remaining_bboxes)) ) ] suppression_mask = ((distances_between_centers<threshold)&(angles_diffs<np.radians(threshold))).astype(bool).tolist() indices_to_remove = set(compress(indices_sorted_by_score,suppression_mask)) indices_sorted_by_score[:] = [idx for idx in indices_sorted_by_score if idx not in indices_to_remove] return [detections[i] for i in keep_indices] ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值