minAreaRect OpenCV [Python] 返回的裁剪矩形 [英] Crop Rectangle returned by minAreaRect OpenCV [Python]
本文介绍了minAreaRect OpenCV [Python] 返回的裁剪矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
minAreaRect
在 OpenCV 中返回一个旋转的矩形.如何裁剪矩形内的这部分图像?
minAreaRect
in OpenCV returns a rotated rectangle. How do I crop this part of the image which is inside the rectangle?
boxPoints
返回旋转矩形角点的坐标,因此可以通过循环访问框内的点来访问像素,但是在 Python 中是否有更快的裁剪方法?
boxPoints
returns the co-ordinates of the corner points of the rotated rectangle so one can access the pixels by looping through the points inside the box, but is there a faster way to crop in Python?
编辑
请参阅下面我的回答中的 code
.
See code
in my answer below.
推荐答案
你没有给出示例代码,所以我也没有代码回答.您可以按以下步骤操作:
You have not given sample code, so I am answering without code also. You could proceed as follows:
- 根据矩形的角,确定相对于水平轴的旋转角度 alpha.
- 按 alpha 旋转图像,使裁剪的矩形与图像边框平行.确保临时图像的尺寸更大,以便不会丢失任何信息(参见:旋转图像而无需裁剪 OpenCV)
- 使用 numpy 切片裁剪图像(参见:如何裁剪使用 Python 的 OpenCV 中的图像)
- 按 -alpha 向后旋转图像.
这篇关于minAreaRect OpenCV [Python] 返回的裁剪矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文