0
我試圖實現在連接組件去除噪聲,在OpencCV 2.3.4的Python API,作爲概述從287頁Learning OpenCV連接零件清潔cv2.arcLength OpenCV的:斷言失敗
開始,據我已經得到計算輪廓的長度,其中我得到一個神祕的斷言錯誤。
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'
任何想法的錯誤意味着以及如何我能得到解決嗎?
哇!有效!我不知道爲多個返回類型放置變量會對輸出產生影響。我實際上已經在使用您的博客作爲指導。 (你可能知道他們的cv2例子的乾旱)所以謝謝! – craastad 2013-02-28 11:43:06
是的,我知道,我想補充更多的樣本,但我的學者不給我很多空閒時間。無論如何,我很高興它的工作! – 2013-02-28 12:54:23