python-3.x - 在 python 中使用 cv2.drawcontours() 时出错
问题描述
我正在应用一些关于绘制轮廓的代码,但出现以下错误: t = cv2.drawContours(img, contours, -1, (0,255,0), 3)
错误:OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2509: 错误: (-215:Assertion failed) npoints > 0 in function 'cv::drawContours '
有人能告诉我问题是什么吗??
解决方案
很难这么说,因为你没有使用代码编辑器......但我猜它来自
thresh = cv2.adaptiveThreshold(img,8,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
t = cv2.drawContours(img, contours, -1, (0,255,0), 3)
缺少 findContours 函数。到目前为止,轮廓对象是空的。在绘图之前,您需要找到它们。 https://docs.opencv.org/4.1.0/d4/d73/tutorial_py_contours_begin.html
推荐阅读
- google-cloud-platform - Google Cloud Bucket - 静态网站错误(使用 NameCheap 域和 Cloudflare CDN)
- r - solve.default(-H) 中的错误:Lapack 例程 dgesv:系统完全是奇异的:U[16,16] = 0
- python - getopt:如何强制存在两个选项?
- android - 如何在 Flutter 中制作键盘应用程序?
- asp.net-core - .netCore 5 区域路由在 RedirectToActionArea 中不起作用并作为查询字符串
- c - dyld:在makefile中链接时未加载库
- python - Django说字段存在时不存在
- javascript - VS Code + jsconfig.json:“找不到模块...”用于具有内置类型的 NPM 模块
- scala - 如何将 Spark/Scala RDD 合并/加入到 List 中,以便 RDD 中的每个值与每个 List 项一起获得一个新行
- javascript - 未使用 wavesurfer 创建的波形