从here运行这段代码时,出现以下错误。
**类型为“ NoneType”的对象没有len()
我的代码:
if len(cnts) > 0:
c = max(cnts, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
if radius > 10:
cv2.circle(frame, (int(x), int(y)), int(radius),
(0, 255, 255), 2)
cv2.circle(frame, center, 5, (0, 0, 255), -1)
pts.appendleft(center)
答案 0 :(得分:0)
改为使用if cnts is not None:
。
答案 1 :(得分:0)
还要检查同一帖子中询问的this answer。建议更新imutils
$ pip install --ugprade imutils