Error using cv2.findContours

I tried to find outlines for the 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)

mistake:

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 use Python 2.7 OpenCV 2.4.7,2.4.11

Any help is appreciated.

+4
source share
1 answer

I solved this problem by updating my version of python to 3.4 and opencv version 3. But I can not find real solutions for this. Why python 2.x versions do not fully support openCV

+1
source

Source: https://habr.com/ru/post/1610090/


All Articles