【发布时间】:2021-10-22 08:17:37
【问题描述】:
我有 yolo 格式的边界框坐标图像。坐标保存在文本文件中。我想翻转所有图像并希望这些图像有新的坐标文本文件。因此,循环将遍历文件夹,加载图像和注释文本文件,翻转图像,生成新的注释文本文件并将图像和注释文件保存在文件夹中。
【问题讨论】:
标签: python image image-processing object-detection yolo
我有 yolo 格式的边界框坐标图像。坐标保存在文本文件中。我想翻转所有图像并希望这些图像有新的坐标文本文件。因此,循环将遍历文件夹,加载图像和注释文本文件,翻转图像,生成新的注释文本文件并将图像和注释文件保存在文件夹中。
【问题讨论】:
标签: python image image-processing object-detection yolo
您好,您只需要更改 x 轴使用此等式:X_new = width -x -1 注意:我的函数中的name操作可以是fliplr或者flip up down
enter code here def flip_anotation(my_path, name_jpg, name_operation, axis=1):
# Handle with flip data
file_data = []
# open file and read the content in a list
with open(os.path.join(my_path, name_jpg + '.txt'), 'r') as myfile:
for line in myfile:
# remove linebreak which is the last character of the string
currentLine = line[:-1]
data = currentLine.split(" ")
# add item to the list
file_data.append(data)
# Change X_center Fliplr
for i in file_data:
i[axis] = str(1 - float(i[axis]) - 1 / img.shape[1])[0:8]
# Write back to the file
f = open(os.path.join(my_path, name_jpg + name_operation + '.txt'), 'w')
for i in file_data:
res = ""
for j in i:
res += j + " "
f.write(res[:-1]) # Save all but ignore from the least " "
f.write("\n")
f.close()
【讨论】: