COCO格式的语义分割数据json,转为png格式,如CityScapes采用的。使用本脚本可以将coco格式转为CityScapes格式的语义标注。语义分割标注转为png图片格式,可便于进行语义分割标注结果可视化,及时查看标注效果。

语义分割标注是对图像每个像素的类别进行标注,采用图片形式标注更加直观。

函数名称为cocojson2png,代码如下所示。

# -*- coding: utf-8 -*-
"""
Created on Fri Apr  8 2022
@author: suiyingy
"""
import cv2
import numpy as np
import os
import json
from collections import defaultdictdef cocojson2png(coco_dir, json_path='instances_train2017.json', cls_type = 'train2017', save_dir = 'res/'):save_path = os.path.join(save_dir, cls_type)if not os.path.exists(save_path):os.makedirs(save_path)annotation_file = os.path.join(coco_dir, 'annotations', json_path)with open(annotation_file, 'r', encoding='utf-8') as annf:annotations = json.load(annf)images = [i['id'] for i in annotations['images']]img_anno = defaultdict(list)for anno in annotations['annotations']:for img_id in images:if anno['image_id'] == img_id:img_anno[img_id].append(anno)imgid_file = {}for im in annotations['images']:imgid_file[im['id']] = im['file_name']for img_idx in img_anno:image = cv2.imread(coco_dir+'images/'+cls_type+'/'+imgid_file[img_idx])h, w, _ = image.shapeinstance_png = np.zeros((h, w), dtype=np.uint8)for idx, ann in enumerate(img_anno[img_idx]):im_mask = np.zeros((h, w), dtype=np.uint8)mask = []for an in ann['segmentation']:ct = np.expand_dims(np.array(an), 0).astype(int)contour = np.stack((ct[:, ::2], ct[:, 1::2])).Tmask.append(contour)imm = cv2.drawContours(im_mask, mask, -1, 1, -1)imm = imm * (1000 * anno['category_id'] + idx)instance_png = instance_png + imminstance_png = np.clip(instance_png,0 ,255)instance_png = np.expand_dims(instance_png,axis=2).repeat(3,axis=2).astype(np.uint8)print(instance_png.shape)cv2.imwrite(os.path.join(save_path, imgid_file[img_idx].split('.')[0]+".png"), instance_png)if __name__ == '__main__':coco_dir = "coco/"cocojson2png(coco_dir, json_path='instances_train2017.json')

更多三维、二维感知算法和金融量化分析算法请关注“乐乐感知学堂”微信公众号,并将持续进行更新。

coco语义分割标注json转png相关推荐

  1. 语义分割标注工具——labelme

    参考下面网址: 感谢up主:https://www.bilibili.com/video/BV1xT4y1j7A9?from=search&seid=2903997967250679674 在 ...

  2. 语义分割标注方式和指标

    语义分割标注方式和指标 前言 分割任务 数据集标注方式 标注工具 评价指标 定义 计算方式 混淆矩阵 Global Acc Mean Acc Mean IoU 总结 参考 前言 这是我看大佬讲语义分割 ...

  3. 【工具】Semantic Segmentation Editor 语义分割标注工具

    [工具]Semantic Segmentation Editor 语义分割标注工具 一.简介 二.界面 1.工具栏 ① 上方横排工具栏 Ctrl + Z 撤销 Ctrl + Y 重做 Alt 操纵工具 ...

  4. python工具方法 18 labelme语义分割标注数据批量转换为png

    本实例代码主要使用labelme.utils.shapes_to_label方法实现批量将将labelme的语义分割标注数据转换为图片,支持将标注保存为实例分割训练图.语义分割训练图.语义分割+原图效 ...

  5. 图像语义分割标注软件EISeg

    paddle 语义分割标注软件: https://github.com/PaddleCV-SIG/EISeghttps://github.com/PaddleCV-SIG/EISeg

  6. coco 语义分割_YOLACT++:目前最热门的实时实例分割开源库

    点击我爱计算机视觉标星,更快获取CVML新技术 YOLACT 是ICCV 2019 接收的实时实例分割论文 YOLACT: Real-time Instance Segmentation 提出的算法, ...

  7. 点云语义分割标注工具及生成训练数据

    1.软件的安装     (1)下载后随便你解压到那个文件夹下(软件github地址)     github链接     (2)在终端中运行: curl https://install.meteor.c ...

  8. labelme——语义分割标注

    labelme安装 1.视频教程 安装使用labelme网络上有很多视频教程,这里推荐一位大神的安装教程,地址如下:https://www.bilibili.com/video/BV16b411G7k ...

  9. (18)语义分割--paddle--EISeg自动标注软件的使用和自己数据集的测试

    1.主要参考 (1)使用过程,建议先看一下下面博主的视频 eiseg简单教学_哔哩哔哩_bilibili (2)软件使用,主要参考! 百度飞浆EISeg高效交互式标注分割软件的使用教程_Leonard ...

最新文章

  1. 《认知设计:提升学习体验的艺术》——学习者喜欢什么
  2. Weex Flexbox弹性布局使用
  3. P1629邮递员送信与P1342请柬与P1821银牛派队研制联合胜利
  4. cisco router修改mac
  5. IOC操作Bean管理XML方式(bean的作用域)
  6. ROS笔记(5) ROS架构
  7. python csv数据所在行_使用python获取csv文本的某行或某列数据的实例
  8. 【渝粤教育】电大中专药剂学基础知识 (2)作业 题库
  9. java enable_Java Compiler enable()方法与示例
  10. 微型计算机原理及应用 湖南大学,2015年微机原理及其应用-湖南大学.doc
  11. 网易公司首席执行官 丁磊
  12. NFT,一种新型社交网络
  13. C#高性能大容量SOCKET并发完成端口例子(有C#客户端)完整实例源码
  14. 黑盒测试设计测试用例的方法【修改】
  15. 组织能力:企业成败的关键(组织能力杨三角系列一)
  16. 软件测试好学习吗?会不会很难入行?
  17. MY1690-12P语音模块实现特定的语音提示功能
  18. 哈希表算法通俗理解和实现
  19. ElasticSearch(十一)Java用ElasticSearch 利用搜索词分词搜索
  20. android apk 自动编译器,Android APK编译流程

热门文章

  1. 微信之父张小龙谈移动互联网产品:我所说的都是错的!
  2. 度量学习方法 - KISSME
  3. python-opencv第一期:imread函数详解
  4. 多伦多大学计算机语言要求,多伦多大学语言要求
  5. PI数据库的应用、管理和定位
  6. 蚂蚁借呗超过20次就会影响贷款吗?
  7. 匿名社交:在安全和危险边缘摇摆
  8. 安装系统服务器部署,部署服务器的安装及配置
  9. QT学习系列:VS2015+QT环境配置后Lauch qt designer失败,无法打开*.ui文件
  10. Shark(鲨鱼记账系统)--附源码