opencv抠出图像中的有角度的矩形框:
import cv2
import numpy as np
def main():
img = cv2.imread("F:/wangjiao/_LB37824S5AX055086_.jpg")
cnt = np.array([
[[215, 381]],
[[1109, 452]],
[[1102, 532]],
[[209, 461]]
])
# cnt = np.array([
# [[281, 573]],
# [[1054, 498]],
# [[1061, 566]],
# [[287, 641]]
# ])
cv2.drawContours(img, [cnt], 0, (0, 255, 255), 2)
rect = cv2.minAreaRect(cnt)
print("rect: {}".format(rect))
box = cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img, [box], 0, (0, 0, 255), 2)
# img_crop will the cropped rectangle, img_rot is the rotated image
img_crop, img_rot = crop_rect(img, rect)
cv2.imwrite("F:\wangjiao/rotate/img.jpg", img)
cv2.imwrite("F:\wangjiao/rotate/cropped_img.jpg", img_crop)
cv2.waitKey(0
opencv抠出图像中的有角度的矩形框
最新推荐文章于 2023-09-24 12:03:29 发布
本文介绍了使用OpenCV从图像中提取倾斜矩形框的两种策略:旋转抠图和透视变换抠图。其中,旋转方法由于采用仿射变换,计算量相对较小。
摘要由CSDN通过智能技术生成