c++读取与写入

来源:互联网 发布:淘宝购买数量点到1000 编辑:程序博客网 时间:2024/05/17 03:26
#include <iostream>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/ml/ml.hpp>
using namespace std;
using namespace cv;
int a,b,c,d,e;
int width,height;
char str3[25];
long long save_num=0;
Mat rect;
Mat src;
int num1=0;
string pattern=" ";
vector< string> split( string str, string pattern)
{
vector<string> ret;
if(pattern.empty()) return ret;
size_t start=0,index=str.find_first_of(pattern,0);
while(index!=str.npos)
{
if(start!=index)
ret.push_back(str.substr(start,index-start));
start=index+1;
index=str.find_first_of(pattern,start);
}
if(!str.substr(start).empty())
ret.push_back(str.substr(start));
return ret;
}
void main()
{
        ifstream in("C:/Users/Administrator/Desktop/pos/thumbResults_nothumb.txt"); 
ofstream out("C:/Users/Administrator/Desktop/pos/thumbResults_nothumb1.txt");
in.eof();
//依次读取正样本图片,生成HOG描述子
for(string s;getline(in,s);) //getline函数只能用于ifstream

//num1++;
vector<string> result=split(s,pattern);
src=imread(result[0]);
cout<<"处理正样本:"<<result[0]<<endl;
a=atoi(result[2].c_str());      
b=atoi(result[3].c_str());
c=atoi(result[4].c_str());
d=atoi(result[5].c_str());

width=c-a;
height=d-b;

result[3]=itoa(cvRound(0.3*double(height))+b,str3,10);
out<<result[0]<<" "<<"1"<<" "<<result[2]<<" "<<result[3]<<" "<<result[4]<<" "<<result[5]<<endl;
}
}

0 0