COCO数据集格式互换
poly->compacted RLE:
seg=np.array([312.29, 562.89, 402.25, 511.49, 400.96, 425.38, 398.39, 372.69, 388.11, 332.85, 318.71, 325.14, 295.58, 305.86, 269.88, 314.86, 258.31, 337.99, 217.19, 321.29, 182.49, 343.13, 141.37, 348.27, 132.37, 358.55, 159.36, 377.83, 116.95, 421.53, 167.07, 499.92, 232.61, 560.32, 300.72, 571.89])
compactedRLE = maskutil.frPyObjects([seg], 768, 768)
print(compactedRLE)
compacted(compressed) RLE->mask:
mask = maskutil.decode(compactedRLE)
mask=np.reshape(mask,(768,768))
mask[:,:]=mask[:,:]*255
print(mask)
#mmcv.imshow(mask)
mask-> polygon / RLE:
def close_contour(contour):
if not np.array_equal(contour[0], contour[-1]):
contour = np.vstack((contour, contour[0]))
return contour
def binary_mask_to_polygon(binary_mask, tolerance=0):
"""Converts a binary mask to COCO polygon representation
Args:
binary_mask: a 2D binary numpy array where '1's represent the object
tolerance: Maximum distance from original points of polygon to approximated
polygonal chain. If tolerance is 0, the original coordinate array is returned.
"""
polygons = []
# pad mask to close contours of shapes which start and end at an edge
padded_binary_mask = np.pad(binary_mask, pad_width=1, mode='constant', constant_values=0)
contours = measure.find_contours(padded_binary_mask, 0.5)
contours = np.subtract(contours, 1)
for contour in contours:
contour = close_contour(contour)
contour = measure.approximate_polygon(contour, tolerance)
if len(contour) < 3:
continue
contour = np.flip(contour, axis=1)
segmentation = contour.ravel().tolist()
# after padding and subtracting 1 we may get -0.5 points in our segmentation
segmentation = [0 if i < 0 else i for i in segmentation]
polygons.append(segmentation)
return polygons
def binary_mask_to_rle(binary_mask):
rle = {'counts': [], 'size': list(binary_mask.shape)}
counts = rle.get('counts')
for i, (value, elements) in enumerate(groupby(binary_mask.ravel(order='F'))):
if i == 0 and value == 1:
counts.append(0)
counts.append(len(list(elements)))
return rle
def main():
mask=np.array(
[
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
)
print(mask)
poly=binary_mask_to_polygon(mask)
print(poly)
rle=binary_mask_to_rle(mask)
print(rle)
COCO数据集格式互换的更多相关文章
- Pascal VOC & COCO数据集介绍 & 转换
目录 Pascal VOC & COCO数据集介绍 Pascal VOC数据集介绍 1. JPEGImages 2. Annotations 3. ImageSets 4. Segmentat ...
- COCO 数据集的使用
Windows 10 编译 Pycocotools 踩坑记 COCO数据库简介 微软发布的COCO数据库, 除了图片以外还提供物体检测, 分割(segmentation)和对图像的语义文本描述信息. ...
- COCO数据集深入理解
TensorExpand/TensorExpand/Object detection/Data_interface/MSCOCO/ 深度学习数据集介绍及相互转换 Object segmentation ...
- 在ubuntu1604上使用aria2下载coco数据集效率非常高
简单的下载方法: 所以这里介绍一种能照顾大多数不能上外网的同学的一种简单便捷,又不会中断的下载方法:系统环境: Ubuntu 14.04 方法: a. 使用aria2 搭配命令行下载.需要先安装: s ...
- MS coco数据集下载
2017年12月02日 23:12:11 阅读数:10411 登录ms-co-co数据集官网,一直不能进入,FQ之后开看到下载链接.有了下载链接下载还是很快的,在我这儿晚上下载,速度能达到7M/s,所 ...
- coco数据集标注图转为二值图python(附代码)
coco数据集大概有8w张以上的图片,而且每幅图都有精确的边缘mask标注. 后面后分享一个labelme标注的json或xml格式转二值图的源码(以备以后使用) 而我现在在研究显著性目标检测,需要的 ...
- COCO数据集使用
一.简介 官方网站:http://cocodataset.org/全称:Microsoft Common Objects in Context (MS COCO)支持任务:Detection.Keyp ...
- 目标检测coco数据集点滴介绍
目标检测coco数据集点滴介绍 1. COCO数据集介绍 MS COCO 是google 开源的大型数据集, 分为目标检测.分割.关键点检测三大任务, 数据集主要由图片和json 标签文件组成. c ...
- 球形环境映射之angular与latlong格式互换
这么做只是纯好奇,因为这种格式互换在实际中是没有意义的,下面映射方式互换的贴图说明了一切. 刚开始打算使用matlab进行贴图映射方式的转换,但许久不用很是生疏,而且生成图片要考虑很多事情,尤其是生成 ...
随机推荐
- Android application 和 activity 标签详解
extends:http://blog.csdn.net/self_study/article/details/54020909 Application 标签 android:allowTaskRep ...
- django-registration
快速开始指南 在安装django-registration之前,你需要先安装Django.django-registration 0.8需要Django1.1或更新版本的支持. Django进一步的信 ...
- c++学习计划
我选择的课程是西北工业大学的<C++程序设计> 理由是:西北工业大学的计算机挺不错的,而且这门课程还有"国家精品"的认证,感觉应该挺不错的. 共48讲...有点多 从2 ...
- 微信小程序本地的域名“不在以下request合法域名列表中”错误处理方法
- 31、cookie小test
请尽量使用JQuery进行代码编写,需求如下: 1. 页面初始化样式如图 2. 顶部input框中输入内容,按下回车enter键后,“正在进行” 列表中加入该条内容. 3. 顶部input框中输 ...
- Linux在终端命令行模式下智能补全功能以及组合键
linux命令行下也有很多热键(快捷键).先来看看tab键 1.如果想看看linux下以c开头的命令可直接在命令行下敲入c然后连续敲两次tab,再选择y,会显示所有以c开头的命令. 2.涉及到文件时, ...
- mybatis主键的生成
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-// ...
- ubuntu 16.04 安装和配置vncserver
https://www.linode.com/docs/applications/remote-desktop/install-vnc-on-ubuntu-16-04/#connect-to-vnc- ...
- CRM项目自定义的知识点
python manage.py shell #自动配置环境 a = models.CustomerInfo #实例对象可以a._meta # dir 可以查看字段方法 a._meta.app_lab ...
- Jedis连接 HelloWorld实现
建一个Maven项目, pom里加下jedis依赖, <dependency> <groupId>redis.clients</groupId> <artif ...