OpenCV--fstream格式化读取坐标数据存为vector

 2023-09-07 阅读 21 评论 0

摘要:输入数据"data.txt" 数据格式如下: 123 234 123 34 131 546 123 767 程序代码 #include <iostream> #include <fstream> #include <opencv2/opencv.hpp>using namespace std; using namespace cv;int main() {ifstream fin;vector<Point2

输入数据"data.txt"
数据格式如下:

123 234
123 34
131 546
123 767

程序代码

#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main()
{ifstream fin;vector<Point2d> pointset;Point2d pts;double temp_x = 0, temp_y = 0;fin.open("data.txt");//!fin.eof() 用来控制什么时候读取终止for (int i = 0; !fin.eof(); i++){//读取txt文件的坐标值fin >> temp_x >> temp_y;pts.x = temp_x;pts.y = temp_y;pointset.push_back(pts);}for (int i = 0; i < pointset.size(); i++){cout << "(" << pointset.at(i).x << "  ,  " << pointset.at(i).y << ")" << endl;}fin.close();system("pause");
}

输出结果
在这里插入图片描述
转载自:
博主:rishown
博文地址:https://blog.csdn.net/rishown/article/details/79738560
来源:CSDN

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/13776.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息