读取一个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. MPU6050陀螺仪和加速度计的校准

    加速度计和陀螺仪的校准: 在传感器静止不动水平放置时,测出陀螺仪和加速度计各轴的偏移值,保存.以后每次上电调用dmp_set_xx_bias()就行了. u8 run_self_test(void) ...

  2. Java – How to get current date time

    Java – How to get current date time 1. Code SnippetsFor java.util.Date, just create a new Date() Dat ...

  3. Another app is currently holding the yum lock; waiting for it to exit.. yum被锁定无法使用

    yum被锁定无法使用 Another app is currently holding the yum lock; waiting for it to exit.. 解决方法: rm -rf /var ...

  4. MySql(十四):MySql架构设计——可扩展性设计之数据切分

    一.前言 通过 MySQL Replication 功能所实现的扩展总是会受到数据库大小的限制,一旦数据库过于庞大,尤其是当写入过于频繁,很难由一台主机支撑的时候,我们还是会面临到扩展瓶颈.这时候,我 ...

  5. eclipse 运行 emulator时,PANIC:Could not open emulator 的解决办法

    使用eclipse启动emulator的时候,出现PANIC:Could not open emulator,模拟器无法正常的运行. 经过搜索得知,因为我的SDK的环境变量出问题,需要重新配置下环境变 ...

  6. (转载)220v交流接触器自锁接线图另接热继电器

    220v交流接触器自锁接线图另接热继电器 时间:2015-06-26 20:36:56编辑:电工栏目:接触器 导读:求一个220v交流接触器自锁接线图,外加个热继电器怎么接,接线图中两根粉色的线接的就 ...

  7. [fixed] 解决 slf4j + log4j eclipse 可以打印日志,而在云服务器上不能打印

    今天发现服务上没有打印任何日志,而log4j已经设置为了INFO 很奇怪,在eclipse中是可以打印的,也能输出到单独的日志中 后来发现原来是冲突了 把log4j注释掉即可 保留slf4j即可

  8. numpy数组-标准化数据

    标准化数据的公式: (数据值 - 平均数) / 标准差 import numpy as np employment = np.array([ 55.70000076, 51.40000153, 50. ...

  9. 【设计模式】装饰器模式与Java Servlet、Spring Session在其中的使用

    简述 装饰器模式,可以通过装饰器类,通过依赖原实现的方式(不使用继承),达到扩展原实现的目的.UML图如下: ServletRequestWrapper于其中的使用 ServletRequestWra ...

  10. Kudu:支持快速分析的新型Hadoop存储系统

    Kudu 是 Cloudera 开源的新型列式存储系统,是 Apache Hadoop 生态圈的新成员之一( incubating ),专门为了对快速变化的数据进行快速的分析,填补了以往 Hadoop ...