以下代码13行为什么报错:NoneType object has no attribute ndimimport cv2 as cvimport numpy as npimport matplotlibpyplot as pltdef showimg if imgndim == 2 pltimshowimg cmap=gray else pltimshowc
可能是因为没有找到任何轮廓,导致变量cnts和hiers都被赋值为None,所以在执行cv.drawContours(mask,cnts,0,255,-1)时出现了'NoneType' object has no attribute 'ndim'的错误。需要在执行findContours之前增加判断,确保找到了轮廓再进行操作。
原文地址: https://www.cveoy.top/t/topic/bMkf 著作权归作者所有。请勿转载和采集!