OpenCV报错 error: (-215) ssize.width > 0 && ssize.height > 0 in function

图像处理入门,在做二值化后轮廓识别时出现报错,使用代码见下。

image=cv2.imread(‘pic.png') imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blurred = cv2.blur(imgray, (9, 9)) (_, thresh0) = cv2.threshold(blurred, 130, 255, cv2.THRESH_BINARY)_,contours,hierarchy= cv2.findContours(thresh0.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) c = sorted(contours, key=cv2.contourArea, reverse=True)[0] rect = cv2.minAreaRect(c) box = np.int0(cv2.boxPoints(rect)) cv2.drawContours(image, [box], -1, (0, 255, 0), 3)Xs = [i[0] for i in box] Ys = [i[1] for i in box] x1 = min(Xs) x2 = max(Xs) y1 = min(Ys) y2 = max(Ys) hight = y2 - y1 width = x2 - x1 imagemidcut = imgray[y1:y1+hight, x1:x1+width]

论坛上的解释为文件路径有问题(使用路径不对或者文件路径中有中文名),检查发现并无类似问题,查看变量,发现y1为一负值(原因现在我也不明白),同一批次其它文件调用时均为出现类似问题。将y1强行修改为一正值后则无报错。
再补充一个帖子,包含error215的
【OpenCV报错 error: (-215) ssize.width > 0 && ssize.height > 0 in function】https://blog.csdn.net/xibeichengf/article/details/50810712

    推荐阅读