我得到了源图像的轮廓。我画了4行来近似这些轮廓:
我想旋转这个矩形,使其与宽度对齐(即图像的x坐标)。
答案 0 :(得分:0)
这可能对您有帮助
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)