下图将告诉你我想要什么.
我有图像中的矩形信息,宽度,高度,中心点和旋转度.现在,我想编写一个脚本来剪切它们并将它们保存为图像,但要理顺它们.因为我想从图像内部显示的矩形转到外面显示的矩形.
我正在使用OpenCV python,请告诉我一种方法来实现这一目标.
请显示一些代码作为OpenCV Python的例子很难找到.

minAreaRect在OpenCV中返回一个旋转的矩形.如何裁剪矩形内部的图像部分?
boxPoints 返回旋转矩形的角点的坐标,这样可以通过循环框内的点来访问像素,但是有更快的方法在Python中裁剪吗?
编辑
请参阅code下面的答案.
这是我得到的一张收据图像,我使用 matplotlib 绘制了它,如果您看到图像,其中的文本不是直的。我该如何去歪斜并修复它?
from skimage import io
import cv2
# x1, y1, x2, y2, x3, y3, x4, y4
bbox_coords = [[20, 68], [336, 68], [336, 100], [20, 100]]
image = io.imread('https://i.ibb.co/3WCsVBc/test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
fig, ax = plt.subplots(figsize=(20, 20))
ax.imshow(gray, cmap='Greys_r')
# for plotting bounding box uncomment the two lines below
#rect = Polygon(bbox_coords, fill=False, linewidth=1, edgecolor='r')
#ax.add_patch(rect)
plt.show()
print(gray.shape)
(847, 486)
Run Code Online (Sandbox Code Playgroud)
我想如果我们想先去歪斜,我们必须找到边缘,所以我尝试使用精明算法找到边缘,然后得到如下所示的轮廓。
from skimage import filters, feature, measure
def edge_detector(image):
image = filters.gaussian(image, 2, mode='reflect')
edges = feature.canny(image) …Run Code Online (Sandbox Code Playgroud)