目标检测:图像填鸭中的旋转+记录角点

PIL库旋转的时候,貌似是不会记录原图旋转后的角点位置【如果可以的话,请大佬告知一下,我学习一下】,所以需要在针对顶点做同样的旋转,然后记录下来。 

关于旋转后角点位置:我参考了这个答案

https://gis.stackexchange.com/questions/23587/how-do-i-rotate-the-polygon-about-an-anchor-point-using-python-script

我是旋转后,随机选择点位粘贴,所以里面会对应坐标系的切换问题。

1:Rotate2D的坐标系是自己设定的坐标系,所以第一步是把这个坐标系转为旋转后图像左下角为(0,0)点的坐标系

def Rotate2D(im_h, im_w, angle):
    pts = scipy.array([[0, 0], [im_w, 0], [im_w, im_h], [0, im_h]])
    cnt = scipy.array([im_w * 0.5, im_h * 0.5])
    ang = scipy.pi * angle / 180
    results = scipy.dot(pts - cnt,
                        scipy.array([[scipy.cos(ang), scipy.sin(ang)], [-scipy.sin(ang), scipy.cos(ang)]])) + cnt
    value_x = []
    value_y = []
    for idx in range(results.shape[0]):
        value_x.append(results[idx][0])
        value_y.append(results[idx][1])
 

你可能感兴趣的:(目标检测-实现)