【发布时间】:2017-04-16 22:48:43
【问题描述】:
我正在尝试编写一个文件(json/yaml/xml,格式无关紧要),该文件存储具有特定cv::Mat 的文件路径。当我最终意识到here 时,组合键不允许路径(例如/home/user)。
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();
}
}
这是cv::FileStorageclass 的真正限制吗?或者有没有办法绕过它?
最终结果应该是这样的:
{
"/my/path/to/file.png": "<my cv::Mat serialization here>",
"/my/path/to/another/file.png": "<my cv::Mat serialization here>",
...
}
观察
错误的发生与格式无关。如果我通过filepath 那
以 yaml/json/xml 结尾,错误是相同的:
如果尝试在键的开头添加一个字母,则会出现以下错误:
这是我在尝试上面的代码时遇到的错误:
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<<
如果我尝试在键的开头添加一个字母,这就是我得到的错误。
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
【问题讨论】: