'tuple' object has no attribute 'sort_contours'
时间: 2023-09-10 10:05:35 浏览: 116
The error message "'tuple' object has no attribute 'sort_contours'" indicates that you are trying to call the method "sort_contours" on a tuple object, but tuples do not have this method.
This error can occur when you are working with OpenCV, as the method "sort_contours" is a method of the cv2 module. To use this method, you need to import cv2 and call it on a list or an array of contours, not a tuple.
Here is an example of how to use the sort_contours method on a list of contours in OpenCV:
```
import cv2
# Define a list of contours
contours = [contour1, contour2, contour3]
# Sort the contours by area
sorted_contours, _ = cv2.sort_contours(contours, key=lambda x: cv2.contourArea(x), reverse=True)
# Now the sorted_contours list contains the contours sorted by area
```
Make sure that your contours are in a list or an array before trying to use the sort_contours method.
阅读全文