how to transform a OpenCV cvMat back to ndarray in numpy ？
Question: I follow the code in OpenCV cookbook for python interface to transform cvMat
to numpy array:

    
    
    mat = cv.CreateMat(3,5,cv.CV_32FC1)
    cv.Set(mat,7)
    a = np.asarray(mat)
    

but with OpenCV 2.1 on my PC, it does not work. The result **a** here is a
object array, using **"print a"** does not print all element in **a** , only
print `<cvmat(type=42424005 rows=3 cols=5 step=20 )>`. so how to fully
transform a **OpenCV Mat object** to original **numpy.ndarray** object.


Answer: Try using appending `[:,:]` to the matrix (ie. use `mat[:,:]` instead of
`mat`) in your call to `np.asarray` \- doing this will also allows `asarray`
to work on images.

Your example:

    
    
    >>> import cv
    >>> import numpy as np
    >>> mat = cv.CreateMat( 3 , 5 , cv.CV_32FC1 )
    >>> cv.Set( mat , 7 )
    >>> a = np.asarray( mat[:,:] )
    >>> a
    array([[ 7.,  7.,  7.,  7.,  7.],
           [ 7.,  7.,  7.,  7.,  7.],
           [ 7.,  7.,  7.,  7.,  7.]], dtype=float32)
    

And for an image:

    
    
    >>> im = cv.CreateImage( ( 5 , 5 ) , 8 , 1 )
    >>> cv.Set( im , 100 )
    >>> im_array = np.asarray( im )
    >>> im_array
    array(<iplimage(nChannels=1 width=5 height=5 widthStep=8 )>, dtype=object)
    >>> im_array = np.asarray( im[:,:] )
    >>> im_array
    array([[100, 100, 100, 100, 100],
           [100, 100, 100, 100, 100],
           [100, 100, 100, 100, 100],
           [100, 100, 100, 100, 100],
           [100, 100, 100, 100, 100]], dtype=uint8)
    

