【发布时间】:2020-10-24 22:36:07
【问题描述】:
这是用相应框翻转图像的python示例之一
是否可以将其写为翻转 20 度角或 20,25 或 45 度角?
如何更改此代码以制作任意角度的角度???
import torchvision.transforms.functional as FT
def flip(image, boxes):
"""
Flip image horizontally.
:param image: image, a PIL Image
:param boxes: bounding boxes in boundary coordinates, a tensor of dimensions (n_objects, 4)
:return: flipped image, updated bounding box coordinates
"""
# Flip image
new_image = FT.hflip(image)
#print('new_image->',new_image)
# Flip boxes
new_boxes = boxes
new_boxes[:, 0] = image.width - boxes[:, 0] - 1
new_boxes[:, 2] = image.width - boxes[:, 2] - 1
new_boxes = new_boxes[:, [2, 1, 0, 3]]
return new_image, new_boxes
【问题讨论】:
标签: pytorch transform torch flip torchvision