2 #include <signal.h>
3 #include <getopt.h>
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <cassert>
8 #include <string>
10 #define MAX_CLASSES 1000
11 #define MAX_SELECTED_ITEMS 100
13 using namespace std;
15 std::string labels_classes[MAX_CLASSES];
16 int IMAGE_CLASSES_NUM = 0;
17 int selected_items_size = 0;
18 int selected_items[MAX_SELECTED_ITEMS];
19 static int get_classindex(std::string str2find)
20 {
21 if(selected_items_size >= MAX_SELECTED_ITEMS)
22 {
23 std::cout << "Max number of selected classes is reached! (" << selected_items_size << ")!" << std::endl;
24 return -1;
25 }
26 for (int i = 0; i < IMAGE_CLASSES_NUM; i ++)
27 {
28 if(labels_classes[i].compare(str2find) == 0)
29 {
30 selected_items[selected_items_size ++] = i;
31 return i;
32 }
33 }
34 std::cout << "Not found: " << str2find << std::endl << std::flush;
35 return -1;
36 }
38 int populate_selected_items (char *filename)
39 {
40 ifstream file(filename);
41 if(file.is_open())
42 {
43 string inputLine;
45 while (getline(file, inputLine) ) //while the end of file is NOT reached
46 {
47 int res = get_classindex(inputLine);
48 std::cout << "Searching for " << inputLine << std::endl;
49 if(res >= 0) {
50 std::cout << "Found: " << res << std::endl;
51 } else {
52 std::cout << "Not Found: " << res << std::endl;
53 }
54 }
55 file.close();
56 }
57 #if 0
58 std::cout << "==Total of " << selected_items_size << " items!" << std::endl;
59 for (int i = 0; i < selected_items_size; i ++)
60 std::cout << i << ") " << selected_items[i] << std::endl;
61 #endif
62 return selected_items_size;
63 }
65 void populate_labels (char *filename)
66 {
67 ifstream file(filename);
68 if(file.is_open())
69 {
70 string inputLine;
72 while (getline(file, inputLine) ) //while the end of file is NOT reached
73 {
74 labels_classes[IMAGE_CLASSES_NUM ++] = string(inputLine);
75 }
76 file.close();
77 }
78 #if 1
79 std::cout << "==Total of " << IMAGE_CLASSES_NUM << " items!" << std::endl;
80 for (int i = 0; i < IMAGE_CLASSES_NUM; i ++)
81 std::cout << i << ") " << labels_classes[i] << std::endl;
82 #endif
83 }