目标检测数据增强:同时切割图片与xml标注

from __future__ import division
import os
from PIL import Image
import xml.dom.minidom
import numpy as np
 
ImgPath = r'D:\code\data\JPEGImages_newname'
AnnoPath = r'D:\code\data\Annotations_newname'
ProcessedPath = r'D:\code\data\output'
    
prefix_str = '''<annotation>
	<folder>VOC2007</folder>
	<filename>{}.jpeg</filename>
	<source>
		<database>The VOC2007 Database</database>
		<annotation>Ring Cell Dataset</annotation>
		<image>flickr</image>
	</source>
	<size>
		<width>2003</width>
		<height>2010</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>'''

 
suffix = '</annotation>'
 
new_head = '''	<object>
		<name>head</name>
		<bndbox>
			<xmin>{}</xmin>
			<ymin>{}</ymin>
			<xmax>{}</xmax>
			<ymax>{}</ymax>
		</bndbox>
		<difficult>0</difficult>
	</object>'''
imagelist = os.listdir(ImgPath)
for image in imagelist:
    image_pre, ext = os.path.splitext(image)#将图片的名称拆成两部分,名称和图片格式
    imgfile = ImgPath + '\\' +  image
    xmlfile = AnnoPath + '\\' + image_pre + '.xml'
 
    DomTree = xml.dom.minidom.parse(xmlfile)  # 打开xml文档
    annotation = DomTree.documentElement  # 得到xml文档对象
 
    filenamelist = annotation.getElementsByTagName('filename')  # [<DOM Element: filename at 0x381f788>]
    filename = filenamelist[0].childNodes[0].data  # 获取XML节点值
    namelist 
  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值