cv2.minAreaRect() 生成最小外接矩形

简介
 
使用python opencv返回点集cnt的最小外接矩形,所用函数为 cv2.minAreaRect(cnt) ,cnt是所要求最小外接矩形的点集数组或向量,这个点集不定个数。
 
1 cv2.minAreaRect(points) → retval
参数说明:
  • points :是findCountours得到的contour
使用
1 import cv2 as cv
2 import numpy as np
3 img = cv.imread("test.jpg",0)
4 _,contours,_ = cv.findContours(img,cv.RETR_LIST,cv.CHAIN_APPROX_SIMPLE)
5 cnt = contours[0]
6 rect = cv.minAreaRect(cnt)#这里得到的是旋转矩形
7 box = cv.cv.BoxPoints(rect)#得到端点
8 box = np.int0(box)#向下取整
 

猜你喜欢

转载自www.cnblogs.com/aoru45/p/9763976.html
今日推荐