imutils.grab_contours的作用

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/nima1994/article/details/90542992

imutils.grab_contours是imutils == 0.5.2(目前版本)中的新功能。imutils.grab_contours经常搭配 cv2.findContours一起使用,如:

cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
			cv2.CHAIN_APPROX_SIMPLE) #1
cnts = imutils.grab_contours(cnts) #2

代码1的作用是寻找轮廓。三个输入参数:输入图像(二值图像,黑色作为背景,白色作为目标),轮廓检索方式,轮廓近似方法。

opencv2返回两个值:contours、hierarchy。opencv3返回三个值:img(图像)、countours(轮廓)、hierarchy(层次结构)。


代码2即 imutils.grab_contours的作用,返回cnts中的countors(轮廓),不区分opencv2或opencv3。可以参考源码: https://github.com/jrosebr1/imutils/blob/master/imutils/convenience.py 。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/nima1994/article/details/90542992