opencv - 如何修复错误:(-215:Assertion failed) npoints > 0 in function 'drawContours'
问题描述
绘制轮廓错误我正在尝试为图像中的对象绘制轮廓
(_, contours) = cv2.findContours(binary, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
# draw contours over original image
length = len(contours)
for c in range(length):
cv2.drawContours(img,contours,c,(255,0,0),3)
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.imshow("output", img)
cv2.waitKey(0)
我希望绘制所有轮廓,但我得到的实际结果是错误:
(-215:断言失败)函数“drawContours”中的 npoints > 0
解决方案
轮廓应该是 numpy 数组。将您的代码更改为:
for c in contours:
cv2.drawContours(img,[c], 0, (255,0,0),3)
推荐阅读
- javascript - 保存使用 readline 模块制作的数组
- javascript - 如何在 React Native 中为 props 设置默认值
- graphql - Gatsby-source-graphql 需要指定选项“fieldName”
- python - 有没有办法从集合中消除所有重复项?
- javascript - 如何在 html、css、react 中制作带有内部文本的箭头?
- python - 使用 python 从网站页面中查找特定单词
- git - 我的域上的 Github 页面返回空白
- javascript - React 组件中另一个文件中的 React JS 调用函数
- ios - 如何使异步请求Swift 5的for循环停止
- sql - T-SQL 窗口函数 - 计算间隙