Commit ef9c773b authored by Davis King's avatar Davis King

Changed the image dataset metadata XML reading tools to use

a map of strings to points to represent object parts.  This
change also removes the old head point from a box since this
information can now be represented in the parts map.
parent dab95b57
......@@ -77,14 +77,19 @@ namespace dlib
if (b.occluded)
fout << " occluded='" << b.occluded << "'";
if (b.has_label() || b.has_head())
if (b.has_label() || b.parts.size() != 0)
{
fout << ">\n";
if (b.has_label())
fout << " <label>" << b.label << "</label>\n";
if (b.has_head())
fout << " <head x='"<< b.head.x() <<"' y='"<< b.head.y() <<"'/>\n";
// save all the parts
std::map<std::string,point>::const_iterator itr;
for (itr = b.parts.begin(); itr != b.parts.end(); ++itr)
{
fout << " <part name='"<< itr->first << "' x='"<< itr->second.x() <<"' y='"<< itr->second.y() <<"'/>\n";
}
fout << " </box>\n";
}
......@@ -141,10 +146,12 @@ namespace dlib
}
virtual void start_element (
const unsigned long ,
const unsigned long line_number,
const std::string& name,
const dlib::attribute_list& atts
)
{
try
{
if (ts.size() == 0)
{
......@@ -183,13 +190,30 @@ namespace dlib
temp_box.rect.bottom() += temp_box.rect.top()-1;
temp_box.rect.right() += temp_box.rect.left()-1;
}
else if (name == "head" && ts.back() == "box")
else if (name == "part" && ts.back() == "box")
{
if (atts.is_in_list("x")) temp_box.head.x() = sa = atts["x"];
else throw dlib::error("<head> missing required attribute 'x'");
point temp;
if (atts.is_in_list("x")) temp.x() = sa = atts["x"];
else throw dlib::error("<part> missing required attribute 'x'");
if (atts.is_in_list("y")) temp_box.head.y() = sa = atts["y"];
else throw dlib::error("<head> missing required attribute 'y'");
if (atts.is_in_list("y")) temp.y() = sa = atts["y"];
else throw dlib::error("<part> missing required attribute 'y'");
if (atts.is_in_list("name"))
{
if (temp_box.parts.count(atts["name"])==0)
{
temp_box.parts[atts["name"]] = temp;
}
else
{
throw dlib::error("<part> with name '" + atts["name"] + "' is defined more than one time in a single box.");
}
}
else
{
throw dlib::error("<part> missing required attribute 'name'");
}
}
else if (name == "image")
{
......@@ -201,6 +225,11 @@ namespace dlib
ts.push_back(name);
}
catch (error& e)
{
throw dlib::error("Error on line " + cast_to_string(line_number) + ": " + e.what());
}
}
virtual void end_element (
const unsigned long ,
......
......@@ -29,7 +29,6 @@ namespace dlib
!*/
box(
) :
head(-0xFFFF,-0xFFFF),
difficult(false),
truncated(false),
occluded(false)
......@@ -37,19 +36,14 @@ namespace dlib
rectangle rect;
std::map<std::string,point> parts;
// optional fields
std::string label;
point head; // a value of (-0xFFFF,-0xFFFF) indicates the field not supplied
bool difficult;
bool truncated;
bool occluded;
bool has_head() const { return head != point(-0xFFFF,-0xFFFF); }
/*!
ensures
- returns true if head metadata is present and false otherwise.
!*/
bool has_label() const { return label.size() != 0; }
/*!
ensures
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment