首页 > 其他分享 >AttributeError: 'tuple' object has no attribute 'sort'

AttributeError: 'tuple' object has no attribute 'sort'

时间:2022-10-08 12:23:16浏览次数:42  
标签:sort APPROX no hierarchy attribute cv2 abs contours

报错

  • 源码
contours, hierarchy = cv2.findContours(img_handled, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
# 据面积排序
contours.sort(key=lambda c: abs(cv2.contourArea(c)), reverse=True)

因为contours是元组没有sort属性
所以更改contours为列表

  • 修改
 contours, hierarchy = cv2.findContours(img_handled, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    # 据面积排序
 contours = list(contours)         # 添加!!!
 contours.sort(key=lambda c: abs(cv2.contourArea(c)), reverse=True)

标签:sort,APPROX,no,hierarchy,attribute,cv2,abs,contours
From: https://www.cnblogs.com/user-yi/p/16768550.html

相关文章