Python openn Cv2绘制等高线
我正在运行此代码,但遇到了一个错误Python openn Cv2绘制等高线,python,opencv,Python,Opencv,我正在运行此代码,但遇到了一个错误 cv2.drawContours(image,contours,-1,(0,255,0),3) error: OpenCV(3.4.3) D:\Build\OpenCV\opencv-3.4.3\modules\imgproc\src\drawing.cpp:2511: error: (-215:Assertion failed) npoints > 0 in function 'cv::drawContours' 收集FindOnTours()的
cv2.drawContours(image,contours,-1,(0,255,0),3)
error: OpenCV(3.4.3) D:\Build\OpenCV\opencv-3.4.3\modules\imgproc\src\drawing.cpp:2511: error: (-215:Assertion failed) npoints > 0 in function 'cv::drawContours'
收集FindOnTours()的输出时,顺序应如下所示:
image, contours, hierarchy = cv2.findContours(...)
在您的具体情况下,您应该写下(我省略了imshow步骤):
image, contours, hierarchy = cv2.findContours(...)
import cv2
import numpy as np
image = cv2.imread("./input1.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edged = cv2.Canny(gray, 30, 200)
_, contours, hierarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
print(f"Number of Contours found = {len(contours)}")
cv2.drawContours(image, contours, -1, (0,255,0), 3)