python – 使用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

点赞