c++读取文件到vector
读取一个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的更多相关文章
- C++读取文件夹中所有的文件或者是特定后缀的文件
由于经常有读取一个文件夹中的很多随机编号的文件,很多时候需要读取某些特定格式的所有文件. 下面的代码可以读取指定文件家中的所有文件和文件夹中格式为jpg的文件 参考: http://www.2cto. ...
- C读取文件
C读取文件,这种写法不会多一行. #include "stdafx.h" #include <vector> using namespace std; struct P ...
- C++读取文件统计单词个数及频率
1.Github链接 GitHub链接地址https://github.com/Zzwenm/PersonProject-C2 2.PSP表格 PSP2.1 Personal Software Pro ...
- c++读取文件夹及子文件夹数据
这里有两种情况:读取文件夹下所有嵌套的子文件夹里的所有文件 和 读取文件夹下的指定子文件夹(或所有子文件夹里指定的文件名) <ps,里面和file文件有关的结构体类型和方法在 <io.h ...
- C++ 按行读取文件并打印
#include<iostream> #include<fstream> #include<string> #include <vector> #inc ...
- Java 创建文件夹和文件,字符串写入文件,读取文件
两个函数如下: TextToFile(..)函数:将字符串写入给定文本文件: createDir(..)函数:创建一个文件夹,有判别是否存在的功能. public void TextToFile(fi ...
- C#读取文件为byte[]
C#读取文件为byte[] 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// 读取程序生成byte /// </sum ...
- HTML5的File API读取文件信息
html结构: <div id="fileImage"></div> <input type="file" value=" ...
- 关于一些对map和整行读取文件操作
public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...
随机推荐
- Happy Java:定义泛型参数的方法
在平时写代码时,可以自定义泛型类.当使用同一类型的对象时,这是非常有用的,但在实例化类之前,我们不知道它将是哪种类型. 下面让我们定义一个使用泛型参数的方法.首先,在定义一个类用到泛型时,必须使用特殊 ...
- sql server中QUOTENAME()函数的用法
操作sql server尤其是写存储过程时,要用到各种各样的函数,今天就总结一个quotename()的用法. 1.语法: quotename('character_string'[,'quote_c ...
- JS实现PC、Android、IOS端的点击按钮复制内容功能
直接上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- django-salmonella的使用
一.django-salmonella介绍 它是一个Django管理员raw_id_fields小部件替换,用于处理更改时显示对象的字符串值,并且可以通过模板覆盖. 二.安装 1.下载 $ pip i ...
- IOS 项目的瘦身工具
http://maniacdev.com/2014/01/tool-a-ruby-gem-allowing-you-to-quickly-find-and-remove-unused-imports- ...
- Linux下找不到so文件的解决办法
http://www.cnblogs.com/xudong-bupt/p/3698294.html 如果使用自己手动生成的动态链接库.so文件,但是这个.so文件,没有加入库文件搜索路劲中,程序运行时 ...
- .NET 获得指定XML配置文件内容
/// <summary> /// 获得指定XML文件内容 /// </summary> /// <param name="strPath">X ...
- 安装mysql提示3306端口已经被占用解决方案
今天遇到的问题是这样的,之前已经安装过mysql了,一直用的好好的,但是今天开启服务时报异常,无法启动.为了省事,于是想到卸载重装,在安装的过程中发现3306已经被占用,这也是一开始服务无法启动的原因 ...
- vim学习笔记(10):vim命令大全
进入vim的命令: vim filename :打开或新建文件,并将光标置于第一行首 vim +n filename :打开文件,并将光标置于第n行首 vim + filename :打开文件,并将光 ...
- Spark SQL inferSchema实现原理探微(Python)【转】
使用Spark SQL的基础是“注册”(Register)若干表,表的一个重要组成部分就是模式,Spark SQL提供两种选项供用户选择: (1)applySchema applySche ...