Opencv:如何使用FileStorage在xml中编写Mat序列
Opencv: how write a sequence of Mat in an xml using FileStorage
我正在尝试将一系列 Mat 元素存储在 xml 文件中。这是我的代码草图
Mat SEQ[3];
int nFrame = 0;
while (1) {
...
...
SEQ[nFrame] = dataAt_nFrame;
if (nFrame == 2) break;
}
FileStorage fs("test.xml", FileStorage::WRITE);
fs << "dataSequence" << SEQ;
fs.release();
cvReleaseCapture(&video1);
FileStorage fs2("test.xml", FileStorage::READ);
Mat SEQ2[3];
fs2["sequence"] >> SEQ2;
//.... here i want print out the values in order to check if are the same i've written...
fs2.release();
while(1) 分析一个视频, 对于每一帧,我得到一个 "dataAt_nFrame",这是一个 Mat。我想将这些数据的整个序列存储在一个数组 SEQ 中(如果您可以建议我更喜欢 Mat [] 类型的替代方案),然后能够读取它们并为每个帧号选择每个 Mat 。
我建议你使用字节数组。这里有一个关于如何将 cv::Mat 转换为字节数组的很好的例子。
您应该尝试sequences/unnamed collection
,例如在链接中。下面的代码不使用它。
#include <string>
std::string toString( int count ) {
return "frame"+std::to_string(count);
}
int nFrame = 0;
FileStorage fs("test.xml", FileStorage::WRITE);
while (1) {
//...
//...
fs << toString(nFrame) << dataAt_nFrame;
}
//saving number of frames in file
fs << "frameCount" << nFrame;
fs.release();
//....
int count=0;
FileStorage fs2("test.xml", FileStorage::READ);
//reading number of frames from file
fs2["frameCount"] >> count;
std::vector<Mat> SEQ2(count);
while( --count >= 0 ) {
//reading individual Mat
fs2[ toString(count) ] >> SEQ2[count];
}
//...
fs2.release();
相关文章:
- 大量序列中核苷酸类型的快速计数
- 递归函数计算序列中的平方和(并输出过程)
- Difference in displaying cv2 Mat
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 从给定的 I 和 D 序列中形成最小数
- 如何在C++中序列化结构数据
- 具有最大子序列大小的序列,每个元素都相同
- 序列化,没有库的整数,得到奇怪的结果
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 算术序列与区间的最大重叠
- 将TPM公钥序列化为DER或PEM
- 算法问题:查找从堆栈中弹出的所有序列
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 如何知道QDataStream不能反序列化某些内容
- 将载体和cv :: mat to Disk的存储结构 - C 中的数据序列化
- 在C++中使用JSON序列化OpenCv Mat
- Opencv:如何使用FileStorage在xml中编写Mat序列
- 在C++中使用 zeromq 将序列化的 Mat 对象发送到另一台计算机
- 使用模板序列(c++,Opencv)编译Mat行
- c++ 如何在 OpenCV 中将视频序列放入矢量<Mat>中?