【问题标题】:Error using cv2.drawcontours(), with python在 python 中使用 cv2.drawcontours() 时出错
【发布时间】:2020-01-03 00:10:49
【问题描述】:

我正在应用一些关于绘制轮廓的代码,但出现以下错误: t = cv2.drawContours(img, 轮廓, -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'

谁能告诉我问题出在哪里??

【问题讨论】:

  • 轮廓是空的吗?
  • 我正在尝试修复代码并将其包含在消息中但系统非常困难我不知道该怎么做这个系统很难使用
  • import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread('00048421.bmp', 0) img = cv2.medianBlur(img, 5) 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) plt.figure(figsize=(12, 12)) plt.imshow(thresh) plt.show()

标签: python-3.x


【解决方案1】:

很难这么说,因为你没有使用代码编辑器......但我猜它来自

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2014-04-04
    • 2015-12-31
    • 2018-05-03
    • 1970-01-01
    相关资源
    最近更新 更多