1、xml文件
import cv2
import os
import argparse
from PIL import Image
import numpy as np
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
import exifread
from PIL.ExifTags import TAGS
def apply_exif_orientation(fname):
ret = {}
try:
image = Image.open(fname)
if hasattr(image, '_getexif' ):
exifinfo = image._getexif()
if exifinfo != None:
for tag, value in exifinfo.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
except IOError:
print ('IOERROR ' + fname)
orientation = ret.get('Orientation', None)
print(ret['Orientation'], orientation)
if orientation == 1:
# do nothing
return image
elif orientation == 2:
# left-to-right mirror
return PIL.ImageOps.mirror(image)
elif orientation == 3:
# rotate 180
return image.transpose(PIL.Image.ROTATE_

这两个Python脚本分别用于将XML和JSON注释文件转换为图像的掩模文件。它们读取图像文件,解析XML或JSON中的几何形状信息,然后使用OpenCV库填充这些形状以创建掩模。脚本处理了图像的Exif方向信息,并支持多类别的图像分割标记。
最低0.47元/天 解锁文章
1700

被折叠的 条评论
为什么被折叠?



