Error when using cv2.findContours

放肆的年华 提交于 2020-01-03 17:48:33

问题


I tried to find contours for image, but it gives an error.

My code is:

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)

error is:

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

I am using Python 2.7 OpenCV 2.4.7,2.4.11

Any help is appreciated.


回答1:


Solved this problem by updating my python version to 3.4 and opencv version 3. But cannot find real solutions for this. Why python 2.x versions not fully support for openCV



来源:https://stackoverflow.com/questions/32922944/error-when-using-cv2-findcontours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!