读取一个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. android安卓系统上运行jar文件

    原文链接: http://blog.sina.com.cn/s/blog_658c8cea0101mdhp.html 步骤如下: 1. 将文件打包成可执行jar文件(可在eclipse里export) ...

  2. Oracle中文乱码解决办法总结

    AMERICAN_AMERICA.WE8ISO8859P1,这个字符编码是西欧字符编码,对应于.Net的就是iso-8859-1字符编码,所以只需要改到系统的默认字符编码就行了. 解决方法: (1) ...

  3. Docker容器进入的4种方式(转)

    在使用Docker创建了容器之后,大家比较关心的就是如何进入该容器了,其实进入Docker容器有好几多种方式,这里我们就讲一下常用的几种进入Docker容器的方法. 进入Docker容器比较常见的几种 ...

  4. 路径不对 导致FileNotFoundError: [WinError 2] 系统找不到指定的文件, 问题解决办法

    执行python + selenium 代码 from selenium import webdriver driver = webdriver.Chrome("D:\AutoConf\bi ...

  5. Viola-Jones人脸检測

    OpenCV中有一个基于树的技术:Haar分类器,它建立了boost筛选式级联. 它能够识别出人脸和其它刚性物体. 对于检測"基本刚性"的物体(脸,汽车,自行车,人体等)这类识别任 ...

  6. android使用百度地图SDK 去掉百度Logo的小技巧

    // 隐藏logoView child = mMapView.getChildAt(1); if (child != null && (child instanceof ImageVi ...

  7. Egret入门了解

    0.前言 这个星期没有什么事做,就想找点技术了解一下.前段时间看过Egret,用来开发HTML5小游戏.一开始以为很麻烦的,但是经过这两天了解了一下,如果用这个游戏引擎来开发一些简单的游戏,还是蛮方便 ...

  8. 【小白的CFD之旅】21 网格划分软件的选择

    但是怎样才能获得流体计算网格呢?“工欲善其事必先利其器”,画网格该用什么器呢?小白决定找黄师姐请教一番. 小白找到黄师姐的时候,黄师姐正在电脑上忙着. “黄师姐,我发现网格划分软件有好多种,究竟哪种才 ...

  9. LL&LR parser

    https://stackoverflow.com/questions/5975741/what-is-the-difference-between-ll-and-lr-parsing https:/ ...

  10. Advanced DataStream API Low-latency Event Time Join

    http://training.data-artisans.com/exercises/eventTimeJoin.html