【问题标题】:How to rotate a rectangle in an image [duplicate]如何旋转图像中的矩形[重复]
【发布时间】:2021-11-27 12:39:54
【问题描述】:

我想在我的图像中移动一个矩形。我发现了如何使用下面的代码在我的图像中获得一个矩形。但是现在我想知道我是否也可以将矩形旋转 30 度。

import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PIL import Image

im = Image.open(r'path...\aero1.jpg')

# Create figure and axes
fig, ax = plt.subplots()

# Display the image
ax.imshow(im)

# Create a Rectangle patch
rect = patches.Rectangle((200, 200), 40, 30, linewidth=1, edgecolor='r', facecolor='none')

# Add the patch to the Axes
ax.add_patch(rect)

plt.show()

【问题讨论】:

    标签: python matplotlib rotation shapes


    【解决方案1】:

    使用angle 参数:

    patches.Rectangle((200, 200), 40, 30, linewidth=1, edgecolor='r', facecolor='none', angle=30)
    

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      相关资源
      最近更新 更多