#这个代码是做二值化图部分,标记连通后取出标记值做二值化图
for uuu in range(len(props.coords)):
y,x = props.coords[uuu]
cropRectSmall[y - y0, x- x0] = 255
#这段代码是获得轮廓,我只要外轮廓即可
cnts = cv2.findContours(cropRectSmall,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
#print(len(contours))
contoursimg = np.zeros((y1 - y0 + 1,x1 - x0 + 1),dtype=np.uint8)
#将list类型的cnts 转换为arry类型
xxxyyy = np.array(cnts[0])
#取出冗余维度,做维度压缩
a_sque = np.squeeze(xxxyyy)
#print(a_sque)
#获得最小外接矩形
rect = cv2.minAreaRect(a_sque)
#将最小外接矩形的box点提取出来
box = cv2.boxPoints(rect)
box = np.int0(box)
#画出来看看
cv2.drawContours(orgimgLAB, [box], 0, (255, 0, 0), 1)
这个是直接在fincounturs函数后打印出轮廓坐标来
for i in range(len(cnts[0])):
#print("==num===", type(cnts[0][i]))
a_sque = np.squeeze(cnts[0][i])
print("
python+opencv做二值化图最小外接矩形提取
最新推荐文章于 2022-06-12 20:30:42 发布
![](https://img-home.csdnimg.cn/images/20240709112858.png)