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 ...
随机推荐
- PAT甲级——A1138 Postorder Traversa【25】
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and in ...
- 修改 ulimit 参数
sudo vim /etc/security/limits.conf 文件下加: * hard nofile 999999 * soft nofile 999999 * soft nproc 1024 ...
- Minifilter 相关
FLTFL_OPERATION_REGISTRATION_SKIP_PAGING_IO 商用软件一定要过滤掉这个类型的请求,这个类型的请求响应非常慢. FLTFL_OPERATION_REGISTRA ...
- C++开发系列-内联函数
内联函数 C++使用内联函数来替代宏代码片段. #include <iostream> int main(){ printfA(); return 0; } inline void pri ...
- 【珍惜时间】vue-websocket
这个项目可能是个有始无终的项目?跟我一起分析吧,比较简单的一个项目 另外,我也想跟自己说,我好像失去了那个努力的自己了.要珍惜时间,好好加油啊~ 项目地址为:https://github.com/xi ...
- Ubuntu Service说明与使用方法
1 什么是Ubuntu的Service 网上很多资料说, service就是linux中随开机自启动的, 并且在后台运行的程序. 个人认为, 至少对于Ubuntu来说, 这个说法是不太准确的, 这只不 ...
- 用Spire.PDF提取PDF里的PNG图片
用Nuget抓取类库,FreeSpire.PDF就可以 代码如下 , 亲测可以抓取PNG图形,即使原图是JPG,也会存成PNG格式输出: //加载PDF文档 PdfDocument doc = new ...
- Servlet和模本办法
抽象类HttpServlet,提供7个子方法的默认实现,当我们手写Servlet只需要继承HttpServlet并替换相应的do方法来完成自己的业务逻辑即可. 我们一般的实现方法: public My ...
- FormData兼容IE10 360及DWR的异步上传原理
摘自:https://github.com/henryluki/FormData/blob/master/formdata.js if(!window.FormData) { (function(se ...
- 模板——网络流Dinic
感谢这位大佬的博客:https://www.cnblogs.com/SYCstudio/p/7260613.html 给予了我莫大的帮助! 主要说一下网络流的几个注意点: 1.和二分图匹配相似,无法继 ...