水平翻转需要注意的事项

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mdjxy63/article/details/83720825

在水平翻转的时候,可以通过image.transpose(PIL.Image.FLIP_LEFT_RIGHT)来进行图像上的水平翻转,但是label并不能和翻转后的图片一一对应,因此需要修改label的横坐标位置

方法1:

通过计算中心点的x坐标来更新

#计算中心点
anno_centers=(anno[:,0]+anno[:,2])/2
#对于中心点进行水平翻转
anno_centers=1-anno_centers
#计算原来的xmin,xmax的距离
anno_widths=anno[:,2]-anno[:,0]
#更新xmin
anno[:,0]=anno_centors-anno_widths/2
#更新xmax
anno[:,2]=anno_centors+anno_widths/2

方法2:参考detectron当中的roidb.py

height,width=image.shape
#获取原来的xmin,xmax
oldxmin=boxes[:,0].copy()
oldxmax=boxes[:,2].copy()
#更新label
boxes[:,0]=width-oldxmax-1
boxes[:,2]=width-oldxmin-1


猜你喜欢

转载自blog.csdn.net/mdjxy63/article/details/83720825