我正在尝试遵循本指南:
我采用相同的样本数据,它们都匹配(缩放、平移、平移、旋转)
我正在尝试制作一个正方形并将其放置在与指南中相同的位置,但在进行更改后我将其放置在不同的位置:
这是我得到的: Rotated
这是我应该得到的: Goal
这是我正在做的事情:
这是我的代码:
data = {
"pattern": {
"scale": 0.438,
"transformation_x": 0.47135912,
"transformation_y": 0.62364169,
"rotation": 96.70385945
}
}
image = Image.open(path)
width, height = image.size
# base
lt = (0, 0)
rt = (width, 0)
lb = (0, height)
rb = (width, height)
# scale
scale = data["pattern"]["scale"]
center = (width/2, height/2)
lt = (center[0]-(width*scale)/2, center[1]-(height*scale)/2)
rt = (center[0]+(width*scale)/2, center[1]-(height*scale)/2)
lb = (center[0]-(width*scale)/2, center[1]+(height*scale)/2)
rb = (center[0]+(width*scale)/2, center[1]+(height*scale)/2)
# transform x
lt = (lt[0]+data["pattern"]["transformation_x"] * width * scale, lt[1])
rt = (rt[0]+data["pattern"]["transformation_x"] * width * scale, rt[1])
lb = (lb[0]+data["pattern"]["transformation_x"] * width * scale, lb[1])
rb = (rb[0]+data["pattern"]["transformation_x"] * width * scale, rb[1])
# transform y
lt = (lt[0], lt[1]+data["pattern"]["transformation_y"] * height * scale)
rt = (rt[0], rt[1]+data["pattern"]["transformation_y"] * height * scale)
lb = (lb[0], lb[1]+data["pattern"]["transformation_y"] * height * scale)
rb = (rb[0], rb[1]+data["pattern"]["transformation_y"] * height * scale)
# rotation
rotated = rotated.rotate(data["pattern"]["rotation"], expand=1, fillcolor=(255, 255, 255))