Code Monkey home page Code Monkey logo

vocdatasetoperation's Introduction

VOCtype-datasetOperation

包含解析VOC数据集、删除指定类别标签,修改指定类别标签名称、批量合并不同标签文件、
剪裁目标图像、画出图中标注框、统计数据集各类别标签数目,resize数据集
Parse VOC dataset, Delete or Correct direction class label, Merge different label file,
Crop object in image, Draw the box of object in image, Statistic the number of label,
resize all image in dataset and correct the annotation information(reszie dataset).
说明文档由中文写作,代码中为英文注释
The documentation is written in Chinese and the code comment is in English.

文件名:

VOCOpertationLibrary.py: VOC数据集中单个xml文件操作函数库
VOC.py:VOC数据集类,操作整个数据集

--VOC类

初始化:

dataset_anno-数据集存储标签的目录
dataset_img-数据集存储图像的目录,可为None
num_class-数据集类别数量,可为None(现在的实现均不需要)

主要方法

_ParseAnnos(self, annodir=None):

分析数据集标注信息,返回一个存储字典的列表,每个字典存在一个图想内的全部标签信息,
{'file':文件名, 'info': 标签类别和坐标, 'size': 图像尺寸}
其中文件名为字符串,
'info'为列表的列表,[[类名, xmin, ymin, xmax, ymax]]
'size'为元组,(宽,高)
输入:annodir-xml文件存储目录,可为空,空self.dataset_anno
输出:列表[[类名, xmin, ymin, xmax, ymax], ...]

_DelAnnotations(self, delclass, annodir=None):

删除数据集指定类别的全部标签信息
输入:delclass-列表,存储全部需要删除的类别名称,['1', '2', ...]
annofile-xml文件目录,若为空,=self.dataset_anno

_Countobject(self, annofile=None):

统计数据集中全部类别标签的数目 输入:annofile-xml文件目录,若为空,=self.dataset_anno 返回:字典,{'类别名称': 统计数目, ...}

_ChangeAnnotation(self, oldcls, newcls, annodir=None):

修改指定类别标签的名称
输入:oldcls-需修改的类别名称
newcls-修改后的类别名称
annofile-xml文件目录,若为空,=self.dataset_anno

_Crop(self, imgdir, cropdir, annos=None):

将数据集中的全部标注框裁剪并保存
输入:imgdir-数据集图像目录;
cropdir-裁剪图像保存目录;
annos-标签信息

_DisplayDirectObjec(self):

显示数据集每个图像的指定目标框,对应每一个图像,显示图像内全部目标框标注信息
选择想要显示的目标框,输入序号,例如:
0 1 2#每个序号间用空格分隔,结束用回车

_Mergeannotation(self, newdataset, olddataset=None):

将俩个数据集(俩个数据集中存在相同的图片)的全部标签合并,合并后存储在olddataset数据集中
此方法的意义:多人分工标注时,将不同人标注的数据合并(例如没人标一类的情况下) 输入:newdataset-需要合并的新数据集
olddataset-需要合并的旧数据集,合并后数据存放在此数据集中

_Resize(self, newsize, annodir=None, imgdir=None):

resize数据集中全部图像,并修改标注信息
输入:newsize-rezise的尺寸,元组,(宽, 高)
annodir-标注xml文件目录
imgdir-图像文件目录

--VOC数据集xml文件操作函数库

_parseannotation(annofile):

分析单个xml文件标注信息,
输入:xml文件地址
返回:列表,[[类名, xmin, ymin, xmax, ymax], ...]

_deletesinglefile(annofile, delclass):

删除单个xml文件的指定类别标签
输入:annofile-xml文件地址
declass-删除的标签类别名称列表

_changeone(annofile, oldcls, newcls, newsize=None):

修改单个xml文件标注信息,当oldcls!=newcls时,可修改指定类别名称
当newsize!=None时,可修改resize图像后的标注信息
输入:annofile-xml文件路径
oldcls-需修改的类别名称
newcls-修改后的类别名称

appendobj(root, annotation):

增加标签信息
输入:root-xml根节点(import xml.etree.ElementTree as ET)
annotation-标签信息,列表,[[类名, xmin, ymin, xmax, ymax], ...]

_mergeone(anno1, anno2):

合并俩个标签xml文件
输入:anno1-标签文件,合并后存储在anno1中
anno2-标签文件

vocdatasetoperation's People

Contributors

a-mockingbird avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.