函数:保存和读取yaml格式数据
2011-04-22 11:45
302 查看
摄像机标定需要用到的数据有:图像的大小,特征点的图像坐标,特征点的世界坐标
saveFeaturePoints函数实现功能:
特征提取后存为文档,为了兼容,最好存为.yaml或.xml格式。但是下面的函数可以存储成任意后缀名,可以“发明”自己的后缀名,用eltraEdit都可以打开。
readFeaturePoints函数可以把数据读出来,以便后面的处理。
例如
int _tmain(int argc, char** argv )
{
vector<Point2f> imagePt;
vector<Point3f> objectPt;
for(int i=0;i<10;i++)
{
imagePt.push_back(Point2f(12.345,54.321));
objectPt.push_back(Point3f(12.345,54.321,67.890));
}
saveFeaturePoints("wyx.yaml",imagePt,objectPt);
vector<Point2f> imagePt1;
vector<Point3f> objectPt1;
readFeaturePoints("wyx.yaml",imagePt1,objectPt1);
saveFeaturePoints("wyx1read.yaml",imagePt1,objectPt1);
}
void saveFeaturePoints(
const string& fileName,
// Size iSize,
vector<Point2f> imagePt,
vector<Point3f> objectPt
)
{
//Save feature points to FILE
FileStorage fs(fileName, FileStorage::WRITE );
//fs << "image_width" << iSize.width;
//fs << "image_height" << iSize.height;
fs << "image_points" << Mat(imagePt);
fs << "object_points" <<Mat(objectPt);
}
bool readFeaturePoints(
const string& fileName,
//Size &iSize,
vector<Point2f> &imagePt,
vector<Point3f> &objectPt
)
{
FileStorage fs(fileName, FileStorage::READ);
if (!fs.isOpened())
return false;
// imagePt.resize(0);
// objectPt.resize(0);
// fs["image_width"] >> iSize.width;
// fs["image_height"] >> iSize.height;
Mat imagePtMat;
fs["image_points"] >> imagePtMat;
imagePt=Mat_<Point2f>(imagePtMat);
Mat objectPtMat;
fs["object_points"] >> objectPtMat;
objectPt=Mat_<Point3f>(objectPtMat);
return true;
}
saveFeaturePoints函数实现功能:
特征提取后存为文档,为了兼容,最好存为.yaml或.xml格式。但是下面的函数可以存储成任意后缀名,可以“发明”自己的后缀名,用eltraEdit都可以打开。
readFeaturePoints函数可以把数据读出来,以便后面的处理。
例如
int _tmain(int argc, char** argv )
{
vector<Point2f> imagePt;
vector<Point3f> objectPt;
for(int i=0;i<10;i++)
{
imagePt.push_back(Point2f(12.345,54.321));
objectPt.push_back(Point3f(12.345,54.321,67.890));
}
saveFeaturePoints("wyx.yaml",imagePt,objectPt);
vector<Point2f> imagePt1;
vector<Point3f> objectPt1;
readFeaturePoints("wyx.yaml",imagePt1,objectPt1);
saveFeaturePoints("wyx1read.yaml",imagePt1,objectPt1);
}
void saveFeaturePoints(
const string& fileName,
// Size iSize,
vector<Point2f> imagePt,
vector<Point3f> objectPt
)
{
//Save feature points to FILE
FileStorage fs(fileName, FileStorage::WRITE );
//fs << "image_width" << iSize.width;
//fs << "image_height" << iSize.height;
fs << "image_points" << Mat(imagePt);
fs << "object_points" <<Mat(objectPt);
}
bool readFeaturePoints(
const string& fileName,
//Size &iSize,
vector<Point2f> &imagePt,
vector<Point3f> &objectPt
)
{
FileStorage fs(fileName, FileStorage::READ);
if (!fs.isOpened())
return false;
// imagePt.resize(0);
// objectPt.resize(0);
// fs["image_width"] >> iSize.width;
// fs["image_height"] >> iSize.height;
Mat imagePtMat;
fs["image_points"] >> imagePtMat;
imagePt=Mat_<Point2f>(imagePtMat);
Mat objectPtMat;
fs["object_points"] >> objectPtMat;
objectPt=Mat_<Point3f>(objectPtMat);
return true;
}
相关文章推荐
- matlab各格式数据读取与保存函数
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
- word 文档的保存数据及读取,类似图片,数据库设置图片格式(image)
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
- python通过串口读取GPS NMEA格式的数据,并保存为csv文件
- C语言sscanf()函数:从字符串中读取指定格式的数据
- 读取含有json格式数据的txt文件 并且把数据保存到数据库
- matlab 中mat格式数据保存与读取
- C编写以二进制读取文件(任意格式eg :图片),保存到C语言数据格式的TXT文档
- mongodb - 前端form表单传递数据,在保存和取出的数据格式处理函数 - 非递归
- matlab imwrite函数保存jpg格式图像丢失数据或改变图像
- C语言sscanf()函数:从字符串中读取指定格式的数据&&C语言strtok()函数:字符串分割
- Python读取windows下记事本保存的UTF-8格式的内容,首行数据显示不正常的解决办法
- Android采用File形式保存与读取数据的方法
- FFMPEG内存操作(二)从内存中读取数及数据格式的转换
- spark 数据的读取与保存
- 读取网址中json数据 转换为java格式
- Linux下获取显存一帧数据并保存为pnm格式图片
- [Linux文件]使用read函数从文件读取数据的实例
- 如何从文本文件读取数据到二维数组,如何在函数处理后返回二维数组的示例