I am trying to write a file (json/yaml/xml, the format does not matter) that stores a filepath with a specific cv::Mat
. As I ended up realizing here, the key combination does not allow for a path (/home/user, for example).
void
persist_histograms(const QString& filepath, const QHash<QString, Mat>& histograms)
{
cv::FileStorage storage(filepath.toStdString(), cv::FileStorage::WRITE);
QHashIterator<QString, Mat> it(histograms);
while (it.hasNext()) {
it.next();
storage << it.key().toStdString() << it.value();
}
}
Is this a real limitation of the cv::FileStorage
class? Or is there a way of going around it?
The end result should be something like:
{
"/my/path/to/file.png": "<my cv::Mat serialization here>",
"/my/path/to/another/file.png": "<my cv::Mat serialization here>",
...
}
Observation
The error occurs independently of the format. If I pass a filepath
that
ends with either yaml/json/xml the errors are the same:
This is the error if a try adding a letter at the beginning of the key:
This is the error I get when trying the code above:
OpenCV Error: Unspecified error (Incorrect element name /home/user/dtd/images/freckled/freckled_0055.jpg) in operator<<, file /build/opencv/src/opencv-3.2.0/modules/core/src/persistence.cpp, line 6877
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv/src/opencv 3.2.0/modules/core/src/persistence.cpp:6877: error: (-2) Incorrect element name /home/user/dtd/images/freckled/freckled_0055.jpg in function operator<<
This is the error I get if I try to add a letter to the beginning of the key.
OpenCV Error: Bad argument (Key names may only contain alphanumeric characters [a-zA-Z0-9], '-', '_' and ' ') in icvJSONWrite, file /build/opencv/src/opencv-3.2.0/modules/core/src/persistence.cpp, line 3896