python生成VOC2007的类库
VOCAnnotation.py:
# -*-coding:utf-8-*-
from lxml import etree
import os class VOCAnnotation(object):
def __init__(self, imageFileName, width, height):
annotation = etree.Element("annotation")
self.__newTextElement(annotation, "folder", "VOC2007")
self.__newTextElement(annotation, "filename", imageFileName) source = self.__newElement(annotation, "source")
self.__newTextElement(source, "database", "P&ID") size = self.__newElement(annotation, "size")
self.__newIntElement(size, "width", width)
self.__newIntElement(size, "height", height)
self.__newIntElement(size, "depth", 3) self.__newTextElement(annotation, "segmented", "0") self._annotation=annotation def __newElement(self, parent, name):
node = etree.SubElement(parent, name)
return node def __newTextElement(self, parent, name, text):
node = self.__newElement(parent, name)
node.text = text def __newIntElement(self, parent, name, num):
node = self.__newElement(parent, name)
node.text = "%d" % num def addBoundingBox(self,xmin,ymin,xmax,ymax,name):
object=self.__newElement(self._annotation,"object") self.__newTextElement(object,"name",name)
self.__newTextElement(object,"pose","Unspecified")
self.__newTextElement(object, "truncated", "0")
self.__newTextElement(object, "difficult", "0") bndbox = self.__newElement(object, "bndbox")
self.__newIntElement(bndbox, "xmin", xmin)
self.__newIntElement(bndbox, "ymin", ymin)
self.__newIntElement(bndbox, "xmax", xmax)
self.__newIntElement(bndbox, "ymax", ymax) def save(self, saveFileName):
tree = etree.ElementTree(self._annotation)
tree.write(saveFileName, pretty_print=True)
Test.py:
#-*-coding:utf-8-*-
import VOCAnnotation
voc=VOCAnnotation.VOCAnnotation("2.png",100,100)
voc.addBoundingBox(1,2,3,4,"a")
voc.save("test.xml")
python生成VOC2007的类库的更多相关文章
- Python生成PASCAL VOC格式的xml标注文件
Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的: <annotatio ...
- JavaScript 解析 Django Python 生成的 datetime 数据 时区问题解决
JavaScript 解析 Django/Python 生成的 datetime 数据 当Web后台使用Django时,后台生成的时间数据类型就是Python类型的. 项目需要将几个时间存储到数据库中 ...
- 【python】【转】Python生成随机数的方法
如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与random模块中最常用的几个函数的关系,希望你会有所收获,以下就是这篇文 ...
- Python生成随机数的方法
这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...
- Python 生成的页面中文乱码问题
第一 保证 程序源文件里的中文的编码格式,如我们把 源文件的编码设置成utf8的. reload(sys) sys.setdefaultencoding('utf-8') 第二, 告诉浏览器,我们须要 ...
- 如何使用python生成xml
最近要用python生成一个xml格式的文件.因为有一些内容是中文,原来的xml文件中使用了CDATA 的部分. 而之前的python程序所用的库中没有 创建这个区域的方法.无奈研究了大半天. 最后用 ...
- python生成随机图形验证码
使用python生成随机图片验证码,需要使用pillow模块 1.安装pillow模块 pip install pillow 2.pillow模块的基本使用 1.创建图片 from PIL impor ...
- Python 生成随机验证码
Python生成随机验证码 Python生成随机验证码,需要使用PIL模块. 安装: 1 pip3 install pillow 基本使用 1. 创建图片 1 2 3 4 5 6 7 8 9 fro ...
- Python生成随机验证码
Python生成随机验证码,需要使用PIL模块. 安装: pip3 install pillow 基本使用 1.创建图片 from PIL import Image img = Image.new(m ...
随机推荐
- Google Chrome浏览器安装xpath helper插件
1. 图中桌面的两个2.0.2_0文件就是xpath helper插件. --------------------------------------------------------------- ...
- 滑雪 矩阵中的最长上升路径 /// 记忆化DFS || DP oj22919
大致题意: Description 难怪Michael喜欢滑雪,因为滑雪确实很刺激.为了获得加速度,滑雪道必须向下倾斜,而且当滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道在一 ...
- 使用CEfSharp之旅(2) js前台事件执行后台方法
原文:使用CEfSharp之旅(2) js前台事件执行后台方法 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https://blo ...
- mybatis 查询sql时foreach使用法
找到俩个例子摘下来 sql查询用户in传list参数 <select id="getEmpsByConditionForeach" resultType="com. ...
- AJAX相关概念及应用
1.Ajax(Asynchronous JavaScript And XML) 异步的JavaScript和XML XML 可扩展标记语言 Ajax是常用的WEB开发技术,是联系前端和后端的桥梁 应用 ...
- openssl操作公私钥和加解密的一些常用命令
生成公私钥实践: 生成私钥,这里以椭圆曲线secp256k1为例: openssl ecparam -name secp256k1 -genkey -out secp256k1-priv.pem #带 ...
- BZOJ2594:水管局长数据加强版
Description SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一 ...
- Java-Druid:Druid
ylbtech-Java-Druid:Druid Apache Druid(孵化)是一个高性能的实时分析数据库. 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 ...
- Lucene 的 Field 域和索引维护
一.Field 域 1.Field 属性 Field 是文档中的域,包括 Field 名和 Field 值两部分,一个文档可以包括多个 Field,Document 只是 Field 的一个承载体,F ...
- django中的request对象
Request 我们知道当URLconf文件匹配到用户输入的路径后,会调用对应的view函数,并将 HttpRequest对象 作为第一个参数传入该函数. 我们来看一看这个HttpRequest对 ...