MCPcopy Create free account
hub / github.com/davisking/dlib / parse_annotation_file

Function parse_annotation_file

tools/imglab/src/convert_idl.cpp:49–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47// ----------------------------------------------------------------------------------------
48
49 void parse_annotation_file(
50 const std::string& file,
51 dlib::image_dataset_metadata::dataset& data
52 )
53 {
54 ifstream fin(file.c_str());
55 if (!fin)
56 throw dlib::error("Unable to open file " + file);
57
58
59 bool in_quote = false;
60 int point_count = 0;
61 bool in_point_list = false;
62 bool saw_any_points = false;
63
64 image img;
65 string label;
66 point p1,p2;
67 while (fin.peek() != EOF)
68 {
69 if (in_point_list && next_is_number(fin))
70 {
71 const int val = read_int(fin);
72 switch (point_count)
73 {
74 case 0: p1.x() = val; break;
75 case 1: p1.y() = val; break;
76 case 2: p2.x() = val; break;
77 case 3: p2.y() = val; break;
78 default:
79 throw dlib::error("parse error in file " + file);
80 }
81
82 ++point_count;
83 }
84
85 char ch = fin.get();
86
87 if (ch == ':')
88 continue;
89
90 if (ch == '"')
91 {
92 in_quote = !in_quote;
93 continue;
94 }
95
96 if (in_quote)
97 {
98 img.filename += ch;
99 continue;
100 }
101
102
103 if (ch == '(')
104 {
105 in_point_list = true;
106 point_count = 0;

Callers 1

convert_idlFunction · 0.70

Calls 7

errorClass · 0.85
next_is_numberFunction · 0.85
read_intFunction · 0.85
rectangleClass · 0.50
getMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected