使用python读取XML文件并对图像进行裁剪
描述:
使用python读取xml文件,获取xml文件标注的区域,在原图像进行裁剪,并保存
代码:
#edit_date:2023-03-18
# function:
#读取文件夹中对应的bmp文件和xml文件,截取图片中对应的坐标的图像
import cv2
import xml.etree.ElementTree as ET
import os
#读取文件中的xml文件和img文件
def readFile(xmlPath,imgPath,savePath):
for img_file in os.listdir(imgPath):
#判断文件后缀属性是否满足图片类型
if img_file[-4:] in ['.bmp','.jpg','.png']:
img_filename=os.path.join(imgPath