使用 cv2.findContours 时出错

Error when using cv2.findContours

我试图找到图像的轮廓,但出现错误。

我的代码是:

import cv2
import numpy as np

img = cv2.imread('star.jpg',0)

ret,thresh = cv2.threshold(img,127,255,0)

contours,hierarchy = cv2.findContours(thresh, 1, 2)

错误是:

Traceback (most recent call last): File "C:\Python27\OpenCVContore.py", line 5, in <module> contours,hierarchy,thresh = cv2.findContours(thresh, 1, 2) error: ........\opencv\modules\core\src\matrix.cpp:236: error: (-215) step[dims-1] == (size_t)CV_ELEM_SIZE(flags) in function cv::Mat::create

我正在使用 Python 2.7 OpenCV 2.4.7,2.4.11

感谢任何帮助。

通过将我的 python 版本更新到 3.4 和 opencv 版本 3 解决了这个问题。但是找不到真正的解决方案。为什么 python 2.x 版本不完全支持 openCV