当前位置: 首页 > news >正文

将scut-seg标签转化成通用coco标签

行人实例分割

import json
import osdef calculate_bounding_rectangle(coordinates):# 提取x和y坐标的列表x_coords = [coord[0] for coord in coordinates]y_coords = [coord[1] for coord in coordinates]# 计算矩形的左上角坐标min_x = min(x_coords)min_y = min(y_coords)# 计算矩形的宽度和高度max_x = max(x_coords)max_y = max(y_coords)width = max_x - min_xheight = max_y - min_yreturn [min_x, min_y, width, height]# scut-seg中的标签
folder_path = r"F:\mcj\AdelaiDet\datasets\dataset-scut\gt_instance\val"
#输出到保存位置
save_path = r"F:\mcj\AdelaiDet\datasets\dataset-scut\gt_instance\person_val_json"
#提取只有行人和骑车人的json文件
for file_name in os.listdir(folder_path):file_path = os.path.join(folder_path, file_name)if file_name.endswith(".json"):flag = Falsewith open(file_path, "r") as load_f:new_dict = json.load(load_f)objects = new_dict['objects']for object in objects :if object['label'] == 'Person' or object['label'] == 'Rider':flag = Trueif flag:target_file = os.path.join(save_path, file_name)with open(target_file,"w") as f:json.dump(new_dict, f)print("step1 finish——提取只有行人和骑车人的json文件")# 构建coco数据json中的字典模板
data = {'categories': [{"id": 1, "name": "person", "color": [128, 0, 0], "supercategory": ""}],'images': [],'annotations': [],'info': "info",'licenses': "licenses"
}
# 图片的标号 从1开始累加
image_id = 1
folder_path = r"F:\mcj\AdelaiDet\datasets\dataset-scut\gt_instance\person_val_json"
save_path = r"F:\mcj\AdelaiDet\datasets\dataset-scut\gt_instance\person_val_json"# 每个标注对象的标号 从1开始累加(文件夹中所有标注对象)
annotation_id = 1
for file_name in os.listdir(folder_path):file_path = os.path.join(folder_path, file_name)image_name = file_name.replace("json", "jpg")temp = {'id': image_id,'width': 720,'height': 576,'file_name': image_name,'license': "",'flickr_url': "",'coco_url': "",'data_captured': ""}data['images'].append(temp)with open(file_path, "r") as load_f:new_dict = json.load(load_f)objects = new_dict['objects']for object in objects:if object['label'] == 'Person' or object['label'] == 'Rider':segmentation = object['polygon']t = []t1 = []for a in segmentation:t.append((a['x'],a['y']))t1.append(a['x'])t1.append(a['y'])rectangle = calculate_bounding_rectangle(t)annotation = {'iscrowd': 0,'id': annotation_id,'image_id': image_id,'category_id': 1,'segmentation': [],'area': 0,'bbox': rectangle}annotation['segmentation'].append(t1)annotation_id += 1data['annotations'].append(annotation)image_id += 1print("step2 finish__转换成coco数据集格式")save_path = r"F:\mcj\AdelaiDet\datasets\dataset-scut\gt_instance\person_val_coco"
target_file = os.path.join(save_path, "val.json")with open(target_file, "w") as f:json.dump(data, f)print("finish-转换成功")
http://www.lryc.cn/news/231233.html

相关文章:

  • 阿里云添加端口
  • Linux组调度
  • 深入解析JavaScript中的变量作用域与声明提升
  • 【Python】jupyter notebook(学习笔记)
  • 红色旅游AR互动体验将景区推向更广泛的市场
  • VR全景:打造虚拟政务服务,打通服务群众“最后一公里”
  • PyCharm 安装库时显示连接超时
  • 那些让我苦笑不得的 Bug:编码之路的坎坷经历
  • http接口测试—自动化测试框架设计
  • HTML 之常用标签的介绍
  • 数据恢复入门分享-启动扇区
  • 解决Chrome无法自动同步书签
  • Java绘图-第19章
  • SpringBoot文件在线预览实现
  • cudnn安装
  • uni-app发布后iOS端页面背景图片上下滑动问题
  • ctfshow 文件上传 151-161
  • Selenium浏览器自动化测试框架简单介绍
  • bclinux aarch64 ceph 14.2.10 文件存储 Ceph File System, 需要部署mds: ceph-deploy mds
  • 【微前端】micro-app搭建项目实战
  • C语言——分割单向链表
  • 台式电脑的IP地址在哪里?解密台式电脑网络连接的秘密!
  • 设计模式案例 (三)
  • JZ22:链表中倒数第k个结点
  • python的高性能web应用的开发与测试实验
  • 除了http还有哪些通信协议?
  • 基于遗传算法的图像重建
  • 【Redis】Redis-Key的使用
  • 为忙碌的软件工程师精心准备的编码面试准备材料,超过 100,000 人受益!
  • SpringCloud Alibaba(上):注册中心-nacos、负载均衡-ribbon、远程调用-feign