title: Connected Component Cleaning cv2.arcLength OpenCv: Assertion Failed
body: <p>I'm trying to implement Connected Component noise removal, in OpencCV 2.3.4 Python API, as outlined starting from page 287 in <a href="http://www.cse.iitk.ac.in/users/vision/dipakmj/papers/OReilly%20Learning%20OpenCV.pdf" rel="nofollow">Learning OpenCV</a></p>
  
  <p>I have got as far as computing the lengths of the contours, in which I get a cryptic assertion error.</p>
  
  <pre><code>OpenCV Error: Assertion failed (curve.checkVector(2) &gt;= 0 &amp;&amp; (curve.depth() == CV_32F || curve.depth() == CV_32S)) in unknown function, file ..\..\..\OpenCV-2.4.3\modules\imgproc\src\contours.cpp, line 1886
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>Any ideas what the error means and how I could get around it?</p>