我尝试为图像查找轮廓,但是出现了错误。
我的代码如下:
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
任何帮助都将不胜感激。
imread
有关。 - Jasonimread
不会抛出任何异常,而是会在后面给你返回各种有趣的错误消息。因此,我使用了自己封装的 Python 包装器来解决这个问题。 - maxy