Ask Your Question

Marcos Nieto's profile - activity

2017-12-20 01:27:38 -0600 received badge  Good Answer (source)
2013-09-25 03:24:47 -0600 received badge  Nice Answer (source)
2013-02-19 03:39:14 -0600 received badge  Teacher (source)
2013-02-19 02:31:49 -0600 received badge  Necromancer (source)
2013-02-19 02:17:06 -0600 received badge  Editor (source)
2013-02-19 02:16:00 -0600 answered a question FileStorage: can write but can't read Size, Rect, etc.

Hi guys. I think the cv::Rect class is written as an array of integers. So that

FileStorage fs(fileName, FileStorage::WRITE);   
Rect r(0,0,0,0);
fs << "myRectangle" << r;

Results in a file with an entry like this:

%YAML:1.0
myRectangle: [ 0, 0, 0, 0 ]

You can access it reading it as a vector of int and (if needed) construct a cv::Rect with its data.

FileStorage fs(fileName, FileStorage::READ);
std::vector<int> rect;
fs["myRectangle"] >> rect;
cv::Rect myRect(rect[0], rect[1], rect[2], rect[3]);

It worked for me! Best regards.