Blame view

res/dump.cpp 1.57 KB
84648488   Chunk   reverted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdlib.h>




#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
#include <fstream>

#include <unistd.h>
#include <string>
#include <string.h>
#include <vector>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <algorithm>

void get_feature(const std::string &file_path, const std::string &outputname) {
	std::string cmd;
	cmd += "../extract/extract_hog ";
	cmd += file_path;
	cmd += " ";
	cmd += outputname;
	//std::cout << cmd << std::endl;
	system(cmd.c_str());
}

int main() {
	std::string from_basedir = "../data/train/";
	std::string to_basedir = "../hog/";
	dirent *ent;
	DIR *pdir = opendir(from_basedir.c_str());
	long cnt = 0;
	
	while ((ent = readdir(pdir)) != NULL) {
		if (strlen(ent->d_name) == 3) {
			std::string dirname = std::string(ent->d_name) + "/";
			DIR *pdir2 = opendir((from_basedir + dirname).c_str());
			system((std::string("mkdir ") + to_basedir + dirname).c_str());

			dirent *ent2;
			while ((ent2 = readdir(pdir2)) != NULL) {
				if (strcmp(ent2->d_name, ".") == 0
						|| strcmp(ent2->d_name, "..") == 0)
					continue;
				std::string imagename = from_basedir + dirname + ent2->d_name;
				std::string outputname = to_basedir + dirname + ent2->d_name;
				outputname = outputname.substr(0, outputname.size() - 3)
						+ "hog";
				//std::cout << imagename << std::endl << outputname << std::endl;
				//std::cout << outputname << std::endl;
				get_feature(imagename, outputname);
				cnt++;
			}
		}
	}
	std::cout << cnt << std::endl;
	return 0;
}