读取一个pts文件到一个vector<Point2f>里面。

其中pts文件如下:

version:
n_points:
{ }
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <fstream>
#include<iostream>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <iostream> #ifdef __APPLE__
#include <sys/uio.h>
#else
#include <sys/io.h>
#endif using namespace cv;
using namespace std; vector<Point2f> readpts(){
ifstream myfile("1.pts");
string temp;
if (!myfile.is_open())
{
cout << "未成功打开文件" << endl;
}
vector<Point2f> vp2f;
int index=;
while(getline(myfile,temp)) {
if((index>=)&&(index<)){
Point2f p1;
int a[]={};
istringstream iss;//istringstream提供读 string 的功能
iss.str(temp);//将 string 类型的 test 复制给 iss,返回 void
string s;
int i=;
while (iss >> s){
int x = stoi(s);
// cout << x << endl;//按空格读取string
a[i]=x;
i++;
}
p1.x=a[];
p1.y=a[];
vp2f.push_back(p1);
}
index++; } return vp2f;
} int main(){ Mat img=imread("1.jpg"); vector<Point2f> landmark= readpts(); for (int idx = ; idx < landmark.size(); idx++) {
cv::circle(img, landmark[idx], , cv::Scalar(, , ), -);
}
imshow("img",img);
cvWaitKey();
return ;
}

c++读取文件到vector的更多相关文章

  1. C++读取文件夹中所有的文件或者是特定后缀的文件

    由于经常有读取一个文件夹中的很多随机编号的文件,很多时候需要读取某些特定格式的所有文件. 下面的代码可以读取指定文件家中的所有文件和文件夹中格式为jpg的文件 参考: http://www.2cto. ...

  2. C读取文件

    C读取文件,这种写法不会多一行. #include "stdafx.h" #include <vector> using namespace std; struct P ...

  3. C++读取文件统计单词个数及频率

    1.Github链接 GitHub链接地址https://github.com/Zzwenm/PersonProject-C2 2.PSP表格 PSP2.1 Personal Software Pro ...

  4. c++读取文件夹及子文件夹数据

    这里有两种情况:读取文件夹下所有嵌套的子文件夹里的所有文件  和 读取文件夹下的指定子文件夹(或所有子文件夹里指定的文件名) <ps,里面和file文件有关的结构体类型和方法在 <io.h ...

  5. C++ 按行读取文件并打印

    #include<iostream> #include<fstream> #include<string> #include <vector> #inc ...

  6. Java 创建文件夹和文件,字符串写入文件,读取文件

    两个函数如下: TextToFile(..)函数:将字符串写入给定文本文件: createDir(..)函数:创建一个文件夹,有判别是否存在的功能. public void TextToFile(fi ...

  7. C#读取文件为byte[]

    C#读取文件为byte[] 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// 读取程序生成byte /// </sum ...

  8. HTML5的File API读取文件信息

    html结构: <div id="fileImage"></div> <input type="file" value=" ...

  9. 关于一些对map和整行读取文件操作

    public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...

随机推荐

  1. SharePoint 2013 Step by Step—— 为终端用户提供故障恢复的解决方案 Part I

    Disaster Recovery,我把他直译"故障恢复",或者也可以翻译成 "灾难复原 ".光字面意思就可以领会到,当SharePoint Server发生了 ...

  2. 使用Python3自带工具2to3.py 转换 Python2.x 代码 到Python3

    几乎所有的Python 2程序都需要一些修改才能正常地运行在Python 3的环境下.为了简化这个转换过程,Python 3自带了一个叫做2to3的实用脚本(Utility Script),这个脚本会 ...

  3. unity, particle system Emit from Edge

  4. django 文档生成器

    参考博客:http://www.liujiangblog.com/course/django/160

  5. 【Android开发】Android应用程序目录结构

    原文:http://android.eoe.cn/topic/summary Android开发之旅:组件生命周期吴秦 Android开发之旅:HelloWorld项目的目录结构 * HelloWor ...

  6. RecyclerView 作为聊天界面,被键盘遮挡的解决办法

    最近项目在重构,使用 RecyclerView 替换了 ListView 作为 IM 的聊天界面.然后遇到了一个问题就是当键盘弹出来的时候,键盘会遮挡住 RecyclerView 的一部分,造成聊天内 ...

  7. sqlserver自定义函数与存储过程的区别 实例详解

    分享下sql server自定义函数与存储过程的区别,一起来学习下. 一.自定义函数: 1. 可以返回表变量 2. 限制颇多,包括 不能使用output参数: 不能用临时表: 函数内部的操作不能影响到 ...

  8. Atitit 软件体系的进化,是否需要一个处理中心

    Atitit 软件体系的进化,是否需要一个处理中心 1.1. 进化树上是没有主干的..1 1.2. ,软件进化的行为1::主要就是给新的应用编写新的程序.1 1.3. ,软件进化的行为2::软件的维护 ...

  9. node调试的两种方法

    刚开始学node.js的时候,一直在用node-inspector,虽然很麻烦,但聊胜于无.后面公司牛人推荐使用node-webkit,就再也没用过node-inspector.再后来node.js版 ...

  10. nginx check_http_send type=http 查检测不到后端TOM的存活

    原因:定位到../conf/server.xml中 <Connector port="8020" protocol="org.apache.coyote.http1 ...