opemcv txt 转MAT,vector到TXT
来源:互联网 发布:企业版软件报盘 编辑:程序博客网 时间:2024/04/30 19:32
{
int retVal = 0;
// 打开文件
ifstream inFile(fileName.c_str(), ios_base::in);
if (!inFile.is_open())
{
cout << "读取文件失败" << endl;
retVal = -1;
}
// 载入数据
istream_iterator<float> begin(inFile); //按 float 格式取文件数据流的起始指针
istream_iterator<float> end; //取文件流的终止位置
vector<KeyPoint> keypoints(begin, end); //将文件数据保存至 std::vector 中
}
void LoadData(string fileName, cv::Mat& matData, int matRows = 0, int matCols = 0, int matChns = 0)
{
int retVal = 0;
// 打开文件
ifstream inFile(fileName.c_str(), ios_base::in);
if (!inFile.is_open())
{
cout << "读取文件失败" << endl;
retVal = -1;
}
// 载入数据
istream_iterator<float> begin(inFile); //按 float 格式取文件数据流的起始指针
istream_iterator<float> end; //取文件流的终止位置
vector<float> inData(begin, end); //将文件数据保存至 std::vector 中
cv::Mat tmpMat = cv::Mat(inData); //将数据由 std::vector 转换为 cv::Mat
// 输出到命令行窗口
//copy(vec.begin(),vec.end(),ostream_iterator<double>(cout,"\t"));
// 检查设定的矩阵尺寸和通道数
size_t dataLength = inData.size();
//1.通道数
if (matChns == 0)
{
matChns = 1;
}
//2.行列数
if (matRows != 0 && matCols == 0)
{
matCols = dataLength / matChns / matRows;
}
else if (matCols != 0 && matRows == 0)
{
matRows = dataLength / matChns / matCols;
}
else if (matCols == 0 && matRows == 0)
{
matRows = dataLength / matChns;
matCols = 1;
}
//3.数据总长度
if (dataLength != (matRows * matCols * matChns))
{
cout << "读入的数据长度 不满足 设定的矩阵尺寸与通道数要求,将按默认方式输出矩阵!" << endl;
retVal = 1;
matChns = 1;
matRows = dataLength;
}
// 将文件数据保存至输出矩阵
matData = tmpMat.reshape(matChns, matRows).clone();
}
Mat shiyan1, shiyan2;
KeyPoint dian1, dian2;
Point2f pot1, pot2;
int shu1 = 0, shu2 = 0;
ofstream outfile1("data1.txt", ios::out);
for (int k = 0; k<keypoints_1.size(); k++)
{
dian1 = keypoints_1[k];
pot1 = dian1.pt;
outfile1 << pot1.x << " , " << pot1.y << endl;
//cout << "[" << pot1.x << " , " << pot1.y << "]" << endl;
++shu1;
}
cout << shu1 << " keypoints in the first image." << endl;
int WriteData(string fileName, cv::Mat& matData)
{
int retVal = 0;
// 打开文件
ofstream outFile(fileName.c_str(), ios_base::out); //按新建或覆盖方式写入
if (!outFile.is_open())
{
cout << "打开文件失败" << endl;
retVal = -1;
return (retVal);
}
// 检查矩阵是否为空
if (matData.empty())
{
cout << "矩阵为空" << endl;
retVal = 1;
return (retVal);
}
// 写入数据
for (int r = 0; r < matData.rows; r++)
{
for (int c = 0; c < matData.cols; c++)
{
uchar data = matData.at<uchar>(r,c); //读取数据,at<type> - type 是矩阵元素的具体数据格式
outFile << data << "\t" ; //每列数据用 tab 隔开
}
outFile << endl; //换行
}
return (retVal);
}
- opemcv txt 转MAT,vector到TXT
- matlab读取txt到.mat
- TXT数据转OpenCV中的Mat数据
- .mat与txt互换
- txt转换为mat
- txt转为mat
- 将matlab 生成的mat矩阵存储到txt中。
- OpenCV读取一张图片的Mat数据类型到.txt文件
- 读取mat文件中特定数据保存到txt中
- mat文件与txt文件的相互转换(特别的,mat转txt,数据格式设置)
- mat文件与txt文件的相互转换(特别的,mat转txt,数据格式设置)
- MATLAB的.mat文件与txt文件的相互转换(mat转txt,数据格式设置)
- Python 读取mat txt 文件
- 如何将vector中的数据写入到txt中
- txt
- TXT
- 将vector<vector<string>>写入TXT文件
- python复制txt内容到另一个txt
- 理解DOM事件流的三个阶段
- RelativeLayout
- YTU.2244: 背包问题(栈和队列)
- java SE 面向对象编程笔记1
- ORACLE监听
- opemcv txt 转MAT,vector到TXT
- C++ GUI Programming with Qt4 Second Edition 之 附录B 编译Qt应用程序
- HTML5 Metadata content(文档元数据)
- Linux_安装tomcat
- Java8新特性Stream流
- jquery+css实现滚动固定侧边栏
- 用模板实现顺序表Vector
- python学习比较 __init__.py 简单使用
- 深入理解java虚拟机之第三章总结(1)