最近在写手写数字的识别软件,训练样例数量巨大而且数字个数不唯一,有可能在中途粘出一部分做测试样例。因此写下面的脚本来获取文件名,之后丢到训练函数里。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> #include <opencv.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/ml/ml.hpp>
#include <opencv2/core/core.hpp>
#include <opencv_modules.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> #define cvQueryHistValue_1D( hist, idx0 ) \
((float)cvGetReal1D( (hist)->bins, (idx0))) using namespace std;
using namespace cv; const string rootDir("./sample/");
const string jpg(".jpg");
const string dirNames[] = {
rootDir + "0/", rootDir + "1/", rootDir + "2/",
rootDir + "3/", rootDir + "4/", rootDir + "5/",
rootDir + "6/", rootDir + "7/", rootDir + "8/",
rootDir + "9/"
}; inline void i2s(string& str, int i, int len = ) {
stringstream ss;
ss << setw(len) << setfill('') << i;
str = ss.str();
} void train(string fileName) { } void getFile(string dirName, int num) {
static int sum = ;
string tmp;
string fileName;
string snum;
stringstream ss;
int cur = ; tmp.clear();
ss << num; ss >> snum;
ifstream fileRead;
for (; ; cur++) {
i2s(tmp, cur);
fileName = dirNames[num] + snum + "_" + tmp + jpg;
if (cur == ) cout << "start file name : " << fileName << endl;
fileRead.open(fileName);
if (!fileRead) {
cout << "end file name : " << fileName << endl;
break;
}
fileRead.close();
train(fileName);
}
sum += cur - ;
cout << "current number of samples : " << sum << endl << endl;
} int main() {
int i = ;
for (int i = ; i != ; i++) {
getFile(dirNames[i], i);
}
return ;
}

巧用ifstream判断文件是否存在的更多相关文章

  1. 转载 - C++ - 关于ifstream/fstream流 判断文件是否结束eof()的问题

    出处:http://blog.csdn.net/shuilan0066/article/details/4669451 在做实验的时候遇到这个问题,找原因的时候发现出处除了讲明原因,还举了例子,所以记 ...

  2. c++ ifstream ofstream 文件流

    #include <fstream>ofstream //文件写操作 内存写入存储设备 ifstream //文件读操作,存储设备读区到内存中fstream //读写操作,对打开的文件可进 ...

  3. C语言中如何判断文件是否存在

    方法一:access函数判断文件夹或者文件是否存在 函数原型: int access(const char *filename, int mode); 所属头文件:io.h filename:可以填写 ...

  4. JavaScript根据文件名判断文件类型

    //JavaScript根据文件名判断文件类型 var imgExt = new Array(".png",".jpg",".jpeg",& ...

  5. PHP判断文件或者目录是否可写

    在PHP中,可用is_writable()函数来判断一个 文件/目录 是否可写,详情如下: 参考 is_writable (PHP 4, PHP 5) is_writable — 判断给定的文件名是否 ...

  6. python os 命令,及判断文件夹是否存在

    使用前 import os导入模块   os模块: os.sep     可以取代操作系统特定的路径分割符 os.linesep  字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...

  7. C# 判断文件有没占用

    C# 判断文件有没占用 using System; using System.Collections.Generic; using System.Text; using System.Runtime. ...

  8. Java 判断文件夹、文件是否存在、否则创建文件夹

    1.判断文件是否存在,不存在创建文件 File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if( ...

  9. php 判断文件或目录是否存在

    判断文件或目录是否存在有自带的函数 file_exists:文件是否存在 $file = "check.txt"; if(file_exists($file)) {     ech ...

随机推荐

  1. 【BZOJ】【1005】【HNOI2008】明明的烦恼

    Prufer序列/排列组合+高精度 窝不会告诉你我是先做了BZOJ1211然后才来做这题的>_>(为什么?因为我以前不会高精度呀……) 在A了BZOJ 1211和1089之后,蒟蒻终于有信 ...

  2. [bzoj 3687]简单题 bitset的运用

    题意 给定一个正整数集,求所有子集算术和的异或和   题解 每次加入一个元素x,用原集合a xor (a<< x) 然后每一个值统计一下 bitset看起来很优越,是一个能位运算的布尔数组 ...

  3. 引擎设计跟踪(九.14.2d) [翻译] shader的跨平台方案之2014

    Origin: http://aras-p.info/blog/2014/03/28/cross-platform-shaders-in-2014/ 简译 translation: 作者在2012年写 ...

  4. 使用css3伪元素制作时间轴并且实现鼠标选中高亮效果

    利用css3来制作时间轴的知识要点:伪元素,以及如何在伪元素上添加锚伪类 1)::before 在元素之前添加内容. 2)::after 在元素之后添加内容. 提示:亦可写成 :before :aft ...

  5. IO端口和IO内存

    为什么会有IO端口和IO内存 这主要原因是因为处理器的架构不同,这里我们使用arm来代表典型的使用IO内存架构,intel 80x86代表典型的使用IO端口架构.简单来说arm把所有寄存器(包括外部设 ...

  6. AIZU 2251

    Merry Christmas Time Limit : 8 sec, Memory Limit : 65536 KB Problem J: Merry Christmas International ...

  7. CLIP PATH (MASK) GENERATOR是一款在线制作生成clip-path路径的工具,可以直接生成SVG代码以及配合Mask制作蒙板。

    CLIP PATH (MASK) GENERATOR是一款在线制作生成clip-path路径的工具,可以直接生成SVG代码以及配合Mask制作蒙板. CLIP PATH (MASK) GENERATO ...

  8. POJ 2182

    #include <iostream> #define MAXN 8005 using namespace std; int _m[MAXN]; int main() { //freope ...

  9. Android loader 详解

    装载器从android3.0开始引进.它使得在activity或fragment中异步加载数据变得简单.装载器具有如下特性: 它们对每个Activity和Fragment都有效. 他们提供了异步加载数 ...

  10. dd大牛的《背包九讲》

    P01: 01背包问题 题目 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 基本思路 这是最 ...