contours,hierarchy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
时间: 2024-01-13 13:10:34 浏览: 28
这段代码使用OpenCV库中的findContours函数在二值图像中查找轮廓(contours)。函数的第一个参数是二值化后的图像(thresh),第二个参数是轮廓的检索模式(RETR_TREE表示提取所有轮廓并建立轮廓之间的层次关系),第三个参数是轮廓的近似方法(CHAIN_APPROX_NONE表示保存所有的轮廓点)。函数返回两个值,contours是包含所有轮廓的列表,hierarchy是包含轮廓之间层次关系的数组。
相关问题
contours, hierarchy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
This line of code finds and retrieves contours from a binary image. The first argument is the input image (in this case, a binary image obtained from thresholding). The second argument specifies the retrieval mode, which determines the relationship between the contours and the hierarchy (parent-child relationships). The third argument specifies the contour approximation method, which determines the level of detail in the contours (in this case, no approximation is used).
The function returns two values: the contours themselves (as a list of arrays), and the hierarchy (a numpy array that describes the relationship between the contours).
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_NONE)
这段代码使用了OpenCV库中的cv2.findContours函数来检测二值化图像中的轮廓。在这段代码中,thresh是输入的二值化图像,cv2.RETR_CCOMP表示检测所有轮廓并建立两级的层次结构,cv2.CHAIN_APPROX_NONE表示存储所有的轮廓点。
函数执行后,会返回两个值:contours和hierarchy。contours是包含检测到的所有轮廓的列表,每个轮廓都表示为一个包含轮廓点的数组。hierarchy是一个包含层次信息的数组,用于描述轮廓之间的关系,如父子关系等。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)