ssd处理灰度图_图像增强方法,SSD有BBOX的情况用这个方法比较好。

参考:

#!/usr/bin/python

# -*- coding: iso-8859-15 -*-

import sys

import os

import shutil

import numpy as np

import imgaug as ia

import xml.etree.ElementTree as ET

from PIL import Image

from imgaug import augmenters as iaa

ia.seed(1)

def read_xml_annotation(root, image_id):

in_file = open(os.path.join(root, image_id))

tree = ET.parse(in_file)

root = tree.getroot()

bndboxlist = []

for object in root.findall('object'):  # 找到root节点下的所有country节点

bndbox = object.find('bndbox')  # 子节点下节点rank的值

xmin = int(bndbox.find('xmin').text)

xmax = int(bndbox.find('xmax').text)

ymin = int(bndbox.find('ymin').text)

ymax = int(bndbox.find('ymax').text)

bndboxlist.append([xmin, ymin, xmax, ymax])

return bndboxlist

def change_xml_annotation(root, image_id, new_target):

new_xmin = new_target[0]

new_ymin = new_target[1]

new_xmax = new_target[2]

new_ymax = new_target[3]

in_file = open(os.path.join(root, str(image_id) + '.xml'))  # 这里root分别由两个意思

tree = ET.parse(in_file)

xmlroot = tree.getroot()

object = xmlroot.find('object')

bndbox = object.find('bndbox')

xmin = bndbox.find('xmin')

xmin.text = str(new_xmin)

ymin = bndbox.find('ymin')

ymin.text = str(new_ymin)

xmax = bndbox.find('xmax')

xmax.text = str(new_xmax)

ymax = bndbox.find('ymax')

ymax.text = str(new_ymax)

tree.write(os.path.join(root, str("%06d" % str(id) + '.xml')))

def change_xml_list_annotation(root, image_id, new_target, saveroot, _id):

in_file = open(os.path.join(root, str(image_id) + '.xml'))  # 这里root分别由两个意思

tree = ET.parse(in_file)

elem = tree.find('filename')

elem.text = _id + '.jpg'

xmlroot = tree.getroot()

index = 0

for object in xmlroot.findall('object'):  # 找到root节点下的所有country节点

bndbox = object.find('bndbox')  # 子节点下节点rank的值

new_xmin = new_target[index][0]

new_ymin = new_target[index][1]

new_xmax = new_target[index][2]

new_ymax = new_target[index][3]

xmin = bndbox.find('xmin')

xmin.text = str(new_xmin)

ymin = bndbox.find('ymin')

ymin.text = str(new_ymin)

xmax = bndbox.find('xmax')

xmax.text = str(new_xmax)

ymax = bndbox.find('ymax')

ymax.text = str(new_ymax)

index = index + 1

tree.write(os.path.join(saveroot, _id + '.xml'))

def mkdir(path):

# 去除首位空格

path = path.strip()

# 去除尾部 \ 符号

path = path.rstrip("\\")

# 判断路径是否存在

isExists = os.path.exists(path)

# 判断结果

if not isExists:

# 如果不存在则创建目录

os.makedirs(path)

print(path + ' 创建成功')

return True

else:

# 如果目录存在则不创建,并提示目录已存在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值