首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV中的旋转轮廓

OpenCV中的旋转轮廓
EN

Stack Overflow用户
提问于 2012-05-01 09:28:50
回答 1查看 5.8K关注 0票数 0

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2018-09-29 01:48:36

这可能对你有帮助

代码语言:javascript
复制
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) 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10395839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档