【问题标题】:How do I flip images with bounding box coordinates?如何使用边界框坐标翻转图像?
【发布时间】:2021-10-22 08:17:37
【问题描述】:

我有 yolo 格式的边界框坐标图像。坐标保存在文本文件中。我想翻转所有图像并希望这些图像有新的坐标文本文件。因此,循环将遍历文件夹,加载图像和注释文本文件,翻转图像,生成新的注释文本文件并将图像和注释文件保存在文件夹中。

【问题讨论】:

    标签: python image image-processing object-detection yolo


    【解决方案1】:

    您好,您只需要更改 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()
    

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 2021-09-03
      • 2021-08-01
      • 2022-01-05
      • 2013-03-03
      • 2019-06-27
      • 2021-02-20
      • 2020-04-26
      • 2020-10-28
      相关资源
      最近更新 更多