我正在尝试在 OpencCV 2.3.4 Python API 中实现连接组件噪声消除,如学习 OpenCV中的第 287 页所述
我已经计算了轮廓的长度,其中我得到了一个神秘的断言错误。
OpenCV Error: Assertion failed (curve.checkVector(2) >= 0 && (curve.depth() == CV_32F || curve.depth() == CV_32S)) in unknown function, file ..\..\..\OpenCV-2.4.3\modules\imgproc\src\contours.cpp, line 1886
这是我的代码:
import cv2
import os
import numpy as np
import cPickle
CVCONTOUR_APPROX_LEVEL = 2
CVCLOSE_ITR = 1
def main():
mask = cv2.imread('input.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
findConnectedComponents(mask)
def findConnectedComponents(mask,
poly1Hull0 = 1,
perimScale = 4,
num = None,
bbs = None,
centers = None):
cv2.morphologyEx(mask, cv2.MORPH_OPEN, np.array(0), iterations=CVCLOSE_ITR)
cv2.morphologyEx(mask, cv2.MORPH_CLOSE, np.array(0), iterations=CVCLOSE_ITR)
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#the Pickle trick solves some strange type errors
tmp = cPickle.dumps(contours)
contours = cPickle.loads(tmp)
for contour in contours:
perimeter = cv2.arcLength(np.array(contour), True)
if __name__ == '__main__':
main()
print 'done'
任何想法错误意味着什么以及我如何解决它?