Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python openn Cv2绘制等高线_Python_Opencv - Fatal编程技术网

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)