title: How to convert a contour list into a numpy array?
body: <p>In this code I want to save all the contours in one <code>.h5</code> file. But this is possible only when I convert the contours to a numpy array.</p>
  
  <pre><code>import numpy as np
  import h5py
  import cv2
  
  thresh,contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
  contours = sorted(contours, key = cv2.contourArea, reverse = False)[40:50]
  l = len(contours)
  cnts = []
  
  for i,contour in enumerate(contours):
      contour = np.array(contour,dtype = np.int32)
      cnts.append(contour)
  
  cnts = np.array(cnts).astype('int32')
  directory = 'Hist_defects'
  os.makedirs(directory,exist_ok = True)
  h = h5py.File('Hist_defects/'+str(k)+'.h5') 
  h.create_dataset('dataset_1',data=cnts)
  h.close()
  </code></pre>
  
  <p>I get the following error when I run this.</p>
  
  <pre><code>cnts = np.array(cnts).astype('int32')
  ValueError: setting an array element with a sequence.
  </code></pre>
  
  <p>Is this kind of conversion possible?</p>