想要打印检测到了多少个轮廓,用了如下的代码:

binary, contours, hierarchy = cv2.findContours(ref.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
res = cv2.drawContours(img, contours, -1, (0, 0, 255), 2)
cv_show('res', res)
# 打印检测到多少个轮廓
print(np.array(contours).shape)

出现了这样的错误:

 这是因为numpy版本的使用问题,修改一下,加上  dtype=object

原始:

print(np.array(contours).shape)

修改为:

print(np.array(contours, dtype=object).shape)

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐