使用cv2.findContours时出错 [英] Error when using cv2.findContours

查看:97
本文介绍了使用cv2.findContours时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到图像的轮廓,但是它给出了一个错误.

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

我的代码是:

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

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

这篇关于使用cv2.findContours时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆