绘制轮廓错误我正在尝试为图像中的对象绘制轮廓
(_, 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:断言失败( n点> 0 在函数 'drawContours' 中
轮廓应该是数字数组。将代码更改为:
for c in contours:
cv2.drawContours(img,[c], 0, (255,0,0),3)
你有轮廓,层次结构向后。请参阅 findContours(( 上的 OpenCv 文档
contours, hierarchy = cv2.findContours(binary,2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)