Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

yea, there is a pitfall with the python FileStorage bindings, it supports only double type for single numbers there (which explains the outcome of your 1st experiment)

but i don't think, the library code needs to be expanded to support vector<int> , this is already handled by the internal vector <--> Mat conversion.

to work around it, you should pass a numpy array here, not a list:

>>> fs = cv2.FileStorage('test.xml', cv2.FILE_STORAGE_WRITE)
>>> a = np.array([1,2,3,4,5])
>>> fs.write("seq_int", a)
>>> fs.release()
>>> quit()

$ cat test.xml
<?xml version="1.0"?>
<opencv_storage>
<seq_int type_id="opencv-matrix">
  <rows>5</rows>
  <cols>1</cols>
  <dt>i</dt>
  <data>
    1 2 3 4 5</data></seq_int>
</opencv_storage>

yea, there is a pitfall with the python FileStorage bindings, it supports only double type for single numbers there (which explains the outcome of your 1st experiment)

but i don't think, the library code needs to be expanded to support vector<int> , this is already handled by the internal vector <--> Mat conversion.

to work around it, you should pass a numpy array here, here (which maps to a cv::Mat), not a list:

>>> fs = cv2.FileStorage('test.xml', cv2.FILE_STORAGE_WRITE)
>>> a = np.array([1,2,3,4,5])
>>> fs.write("seq_int", a)
>>> fs.release()
>>> quit()

$ cat test.xml
<?xml version="1.0"?>
<opencv_storage>
<seq_int type_id="opencv-matrix">
  <rows>5</rows>
  <cols>1</cols>
  <dt>i</dt>
  <data>
    1 2 3 4 5</data></seq_int>
</opencv_storage>

yea, there is a pitfall with the python FileStorage bindings, it supports only double type for single numbers there (which explains the outcome of your 1st experiment)

but i don't think, the library code needs to be expanded to support vector<int> , this is already handled by the internal vector <--> Mat conversion.conversion. (also: what about other types ? reading it back ?)

to work around it, you should pass a numpy array here (which maps to a cv::Mat), not a list:

>>> fs = cv2.FileStorage('test.xml', cv2.FILE_STORAGE_WRITE)
>>> a = np.array([1,2,3,4,5])
>>> fs.write("seq_int", a)
>>> fs.release()
>>> quit()

$ cat test.xml
<?xml version="1.0"?>
<opencv_storage>
<seq_int type_id="opencv-matrix">
  <rows>5</rows>
  <cols>1</cols>
  <dt>i</dt>
  <data>
    1 2 3 4 5</data></seq_int>
</opencv_storage>