为什么print(type(contours))返回的tuple不是list
时间: 2024-03-23 21:41:46 浏览: 23
`cv2.findContours()` 函数返回的不是元组(tuple),而是两个值的二元组(tuple),其中第一个值是轮廓组成的列表,第二个值是轮廓的层次结构。因此,用 `type()` 函数输出 `contours` 的类型得到的结果是 `tuple`,而不是 `list`。
如果你只想获取轮廓的列表(即第一个值),可以这样写:
```python
contours, hierarchy = cv2.findContours(image, mode, method)
print(type(contours)) # 输出 <class 'list'>
```
这样输出的类型就是 `list` 了。
相关问题
contours的属性是list还是tuple
在 OpenCV 中,函数 `cv2.findContours()` 找到的轮廓是一个由 numpy 数组组成的列表(list),其中每个元素表示一个轮廓,每个轮廓又是一个由若干个点坐标构成的 numpy 数组(ndarray),表示轮廓上的点。因此,轮廓的属性是一个列表,其中每个元素是一个 numpy 数组(ndarray),而不是元组(tuple)。
contours is not a numerical tuple
"Contours" is not a numerical tuple because it is a list of numpy arrays, where each array contains the (x,y) coordinates of the contour. Each contour represents a connected component in an image, and can be used for tasks such as object detection, segmentation and tracking. To perform numerical operations on contours, you need to extract the relevant information from the contour arrays, such as the centroid or area, and convert them into numerical tuples.