我得到了源图像的轮廓。我画了四条线来近似这些轮廓:
我想旋转这个矩形,使它与宽度对齐(即图像的x坐标)。
发布于 2018-09-29 01:48:36
这可能对你有帮助
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) https://stackoverflow.com/questions/10395839
复制相似问题