【问题标题】:Rotating contour in OpenCVOpenCV中的旋转轮廓
【发布时间】:2012-05-01 09:28:50
【问题描述】:

我得到了源图像的轮廓。我画了 4 条线来近似这些轮廓:

  1. 从轮廓的最小宽度到最小高度。
  2. 轮廓的最小宽度到最大高度。
  3. 从轮廓的最大宽度到最小高度。
  4. 轮廓的最大宽度到最大高度。

我想旋转这个矩形,使其与宽度对齐(即图像的 x 坐标)。

【问题讨论】:

标签: opencv


【解决方案1】:

这可能对你有帮助

rect = cv2.minAreaRect(yourcontour)
angle = rect[2]

if angle < -45:
    angle = (90 + angle)

# otherwise, just take the inverse of the angle to make
# it positive
else:
    angle = -angle  

# rotate the image to deskew it
(h, w) = img.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(img, M, (w, h),
    flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2014-07-12
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多