Я пытаюсь получить новые координаты после поворота изображения.Но у меня есть координаты, которые являются относительными координатами.Все четыре координаты состоят из значений от 0 до 1. Например (x1, y1) = [0,15, 0,15] (x2, y2) = [0,8, 0,15] (x3, y3) = [0,8, 0,8] (x4,y4) = [0.15, 0.8] Я хочу получить новые координаты x, y при повороте изображения на n градусов.
image = Image.open(os.path.join('./AlignImages', image_name))
labels = np.array(list(map(float, a.split(" ")[1:]))).astype('float32')
#if labels == [0.1 0.1 0.5 0.1 0.5 0.5 0.1 0.5] [x1 y1 x2 y2 x3 y3 x4 y4]
labels = np.vstack((labels[0::2], labels[1::2]))
# [0.1 0.5 0.5 0.1] [x1 x2 x3 x4]
# [0.1 0.1 0.5 0.5] [y1 y2 y3 y4]
print(labels)
labels = np.array([[labels[0][0]-0.5, labels[0][1]-0.5, labels[0][2]-0.5, labels[0][3]-0.5],[0.5-labels[1][0], 0.5-labels[1][1], 0.5-labels[1][2], 0.5-labels[1][3]]])
#This is to move the center point of the image.
#Adjust the value to rotate because the upper left corner of the image is (0, 0)
image = image.rotate(rotation_scale, expand=True)
#I gave the option to expand the image so that the rotated image was not cropped.
image.show()
rotation_ = np.array([[np.cos(rotation_scale), (np.sin(rotation_scale))],[-1*np.sin(rotation_scale), np.cos(rotation_scale)]])
#I have defined a transformation matrix.
src = np.matmul(rotation_, labels)
#Multiply the transformation matrix by the coordinates to obtain the new coordinates.
src = np.array([[src[0][0]+0.5, src[0][1]+0.5, src[0][2]+0.5, src[0][3]+0.5],[0.5+src[1][0], 0.5+src[1][1], 0.5+src[1][2], 0.5+src[1][3]]])
#Let the top left corner be 0, 0 again.
print(src)
[[ 0.24779222 1.00296445 0.7265248 -0.05902794]
[ 0.8065444 0.41615766 0.2350563 0.60667523]]
Однако этот код, похоже, не работает.Я думал, что смогу получить четыре относительные координаты повернутого изображения в этом исходном коде, но это было совсем не так.Я хочу получить относительные координаты четырех вершин в развернутом изображении (повернутое изображение).Все значения должны быть в диапазоне от 0 до 1. Как получить четыре желаемые координаты?