Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

"TypeError: expected a single-segment buffer object" when calling cv.SaveImage

Hi there,

I am trying to convert a numpy array into a cvmat and then save it. The following commandos executed in the interpreter produce an error:

In [21]: type(background)
Out[21]: numpy.ndarray

In [22]: background = cv.fromarray(background)

In [23]: type(background)
Out[23]: cv2.cv.cvmat

In [24]: cv.SaveImage(os.path.join(image_path,"background.tif"),background)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: expected a single-segment buffer object

There is an image created even when the error is thrown but the image is warped. Also, this error doesn't occur if I call the script containing the commandos but the resulting image is warped nevertheless.

When I create a dummy array, the converting and saving process are working perfectly fine:

In [38]: a = reshape(np.array(xrange(16)),(4,4))

In [39]: type(a)
Out[39]: numpy.ndarray

In [40]: a = cv.fromarray(a)

In [41]: type(a)
Out[41]: cv2.cv.cvmat

In [42]: cv.SaveImage(os.path.join(image_path,"test.tif"),a)

Is there a difference between one numpy.ndarray and the other? Could the data type contained in the arrays cause the problem? I am really lost here and would greatly appreciate any help!

openCV version 2.4.3; Python 2.7; Windows 7 64 bit