标签:
<img src="http://img.blog.csdn.net/20160427145905002?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" style="font-family: Arial, Helvetica, sans-serif;" alt="" /><span style="font-family: Arial, Helvetica, sans-serif;">//目标格式:地址,单幅图片包含的目标数,目标1坐标(x0,y0,x1,y1),目标2坐标(x0,y0,x1,y1)....</span>
/************************************director by hengguan*************************************/ //数据必须不等于0; //原版基础上,修正了负数的提示,并且单个文档可读入多组个数据,而不是每个文档只读入1组数据 //本代码适用 VOC2011,VOC2007,INria等数据库 #include<iostream> #include <fstream> #include <string> #include <vector> #include <sstream> #include <stdio.h> #include<io.h> using namespace std; //要读取的文件夹路径 #define Basic_Path "E:\\data\\INria\\posGt\\" //要存放的路径地址的基路径,可以选择Basic_path,也可以修改此路径 #define Set_Path "/home/jack/Desktop/data/pos/" //目标存档文件路径,需要先创建好此文档 #define F_info "C:\\Users\\admin\\Desktop\\data1.txt" bool JudgeNum(string str, int& iTmp, string path) { bool bNum = true; string::size_type szSize = str.size(); //判断是否为数字 for (int i = 0; i<szSize; ++i) { char ch = str.at(i); if ((ch < '0') || (ch > '9')) { if (ch ==45) { cout << path <<"中包含小于0的数"<< endl; <h1> break;</h1> } bNum = false; break; } } if (bNum) { istringstream iss(str); iss >> iTmp; } //判断数字是否为单个0 /*if (iTmp == 0) { bNum = false; }*/ return bNum; } int a, b, c, d; vector<int> iVec; string strTmp; int iTmp = 0, B_num = 0, Coor_num , Object_num; string file_path; bool end_if=true; int main() { _finddata_t file; long lf; FILE *pfile; ifstream icin; //init(); //创建文件流 fstream output_stream; //输入文件夹路径 if ((lf = _findfirst(Basic_Path"*.txt", &file)) == -1) cout << "Not Found!" << endl; else{ //输出文件名 do { Coor_num = 0; file_path = file.name; //读取文件夹下的文件 icin.open(Basic_Path+file_path); if (!icin) { return -1; } while (getline(icin, strTmp, ' ')) // 以空格为分隔符,读取每一个词 { if (JudgeNum(strTmp, iTmp, file_path)) { if (iTmp != 0) { iVec.push_back(iTmp); Coor_num++; } //else //num_zero++; //end_if = false; } //if (end_if == false) //break; } vector<int>::size_type stCnt = iVec.size(); /*if (stCnt >= 4) { a = iVec.at(0 + B_num*4); b = iVec.at(1 + B_num * 4); c = iVec.at(2 + B_num * 4)+a; d = iVec.at(3 + B_num * 4)+b; B_num++; cout << a << " " << b << " " << c << " " << d<<endl; }*/ output_stream.open(F_info, ios::out | ios::app); //output_stream << a << " " << b << " " << c << " " << d << " " << Basic_Path + file_path << endl; //output_stream << a << " " << b << " " << c << " " << d << " " << Set_Path + file_path << endl; //输出到文档,输出文件地址; output_stream << Set_Path + file_path << " "; //输出到文档,输出图片中目标数量,以及目标地址; output_stream << (Coor_num / 4); while (Coor_num / 4) { a = iVec.at(0 + B_num * 4); b = iVec.at(1 + B_num * 4); c = iVec.at(2 + B_num * 4) + a; d = iVec.at(3 + B_num * 4) + b; B_num++; output_stream << " " << a << " " << b << " " << c << " " << d; Coor_num-=4; } if (!(Coor_num / 4)) { output_stream << endl; } end_if = true; icin.close(); output_stream.close(); } while (_findnext(lf, &file) == 0); } _findclose(lf); system("pause"); return 0; }
标签:
原文地址:http://blog.csdn.net/ppp036/article/details/51233279