Skip to content

Commit

Permalink
Changed code to avoid compiler warnings. Also added support for the
Browse files Browse the repository at this point in the history
difficult, truncated, and occluded metadata fields of the pascal datasets.
  • Loading branch information
davisking committed Dec 16, 2011
1 parent 0ac4a54 commit dcb8b6f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tools/imglab/src/convert_pascal_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ namespace
}
else if (words.size() > 4 && (words[2] == "for" || words[2] == "on") && words[3] == "object")
{
int idx = sa = words[4];
long idx = sa = words[4];
--idx;
if (idx >= img.boxes.size())
if (idx >= (long)img.boxes.size())
throw dlib::error("Invalid object id number of " + words[4]);

if (words[0] == "Center" && words[1] == "point" && words.size() > 9)
Expand Down
39 changes: 36 additions & 3 deletions tools/imglab/src/convert_pascal_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ namespace
}

virtual void start_element (
const unsigned long line_number,
const unsigned long ,
const std::string& name,
const dlib::attribute_list& atts
const dlib::attribute_list&
)
{
if (ts.size() == 0 && name != "annotation")
Expand All @@ -66,7 +66,7 @@ namespace
}

virtual void end_element (
const unsigned long line_number,
const unsigned long ,
const std::string& name
)
{
Expand Down Expand Up @@ -106,6 +106,39 @@ namespace
{
temp_box.label = trim(data);
}
else if (ts.back() == "difficult" && ts[ts.size()-2] == "object")
{
if (trim(data) == "0" || trim(data) == "false")
{
temp_box.difficult = false;
}
else
{
temp_box.difficult = true;
}
}
else if (ts.back() == "truncated" && ts[ts.size()-2] == "object")
{
if (trim(data) == "0" || trim(data) == "false")
{
temp_box.truncated = false;
}
else
{
temp_box.truncated = true;
}
}
else if (ts.back() == "occluded" && ts[ts.size()-2] == "object")
{
if (trim(data) == "0" || trim(data) == "false")
{
temp_box.occluded = false;
}
else
{
temp_box.occluded = true;
}
}

}
}
Expand Down
14 changes: 12 additions & 2 deletions tools/imglab/src/image_dataset_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace dlib
<< "left='" << b.rect.left() << "' "
<< "width='" << b.rect.width() << "' "
<< "height='" << b.rect.height() << "'";
if (b.difficult)
fout << " difficult='" << b.difficult << "'";
if (b.truncated)
fout << " truncated='" << b.truncated << "'";
if (b.occluded)
fout << " occluded='" << b.occluded << "'";

if (b.has_label() || b.has_head())
{
Expand Down Expand Up @@ -135,7 +141,7 @@ namespace dlib
}

virtual void start_element (
const unsigned long line_number,
const unsigned long ,
const std::string& name,
const dlib::attribute_list& atts
)
Expand Down Expand Up @@ -170,6 +176,10 @@ namespace dlib
if (atts.is_in_list("height")) temp_box.rect.bottom() = sa = atts["height"];
else throw dlib::error("<box> missing required attribute 'height'");

if (atts.is_in_list("difficult")) temp_box.difficult = sa = atts["difficult"];
if (atts.is_in_list("truncated")) temp_box.truncated = sa = atts["truncated"];
if (atts.is_in_list("occluded")) temp_box.occluded = sa = atts["occluded"];

temp_box.rect.bottom() += temp_box.rect.top()-1;
temp_box.rect.right() += temp_box.rect.left()-1;
}
Expand All @@ -193,7 +203,7 @@ namespace dlib
}

virtual void end_element (
const unsigned long line_number,
const unsigned long ,
const std::string& name
)
{
Expand Down
11 changes: 10 additions & 1 deletion tools/imglab/src/image_dataset_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ namespace dlib
{
struct box
{
box() : head(-0xFFFF,-0xFFFF) {}
box(
) :
head(-0xFFFF,-0xFFFF),
difficult(false),
truncated(false),
occluded(false)
{}

rectangle rect;

// 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); }
bool has_label() const { return label.size() != 0; }
Expand Down

0 comments on commit dcb8b6f

Please sign in to comment.