Skip to content

Commit c1fbfb5

Browse files
authored
full_object_detection: API Support for dpoint (#2183) (#3095)
- Add constructor accepting parts as std::vector<dpoint> - Internally switch parts representation to std::vector<dpoint> - Update serialization logic to version 2 to support dpoint - Deprecate constructor that takes std::vector<point>
1 parent 57547b9 commit c1fbfb5

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

dlib/data_io/load_image_dataset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ namespace dlib
406406
}
407407
else
408408
{
409-
std::vector<point> partlist(parts_idx.size(), OBJECT_PART_NOT_PRESENT);
409+
std::vector<dpoint> partlist(parts_idx.size(), OBJECT_PART_NOT_PRESENT);
410410

411411
// populate partlist with all the parts present in this box.
412412
const std::map<std::string,point>& parts = data.images[i].boxes[j].parts;

dlib/image_processing/full_object_detection.h

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ namespace dlib
1313

1414
// ----------------------------------------------------------------------------------------
1515

16-
const static point OBJECT_PART_NOT_PRESENT(0x7FFFFFFF,
17-
0x7FFFFFFF);
16+
const static dpoint OBJECT_PART_NOT_PRESENT(0x7FFFFFFFFFFFF,
17+
0x7FFFFFFFFFFFF);
1818

1919
// ----------------------------------------------------------------------------------------
2020

@@ -23,9 +23,15 @@ namespace dlib
2323
public:
2424
full_object_detection(
2525
const rectangle& rect_,
26-
const std::vector<point>& parts_
26+
const std::vector<dpoint>& parts_
2727
) : rect(rect_), parts(parts_) {}
2828

29+
full_object_detection(
30+
const rectangle& rect_,
31+
const std::vector<point>& parts_
32+
) : rect(rect_), parts (parts_.begin(), parts_.end())
33+
{}
34+
2935
full_object_detection(){}
3036

3137
explicit full_object_detection(
@@ -36,13 +42,13 @@ namespace dlib
3642
rectangle& get_rect() { return rect; }
3743
unsigned long num_parts() const { return parts.size(); }
3844

39-
const point& part(
45+
const dpoint& part(
4046
unsigned long idx
4147
) const
4248
{
4349
// make sure requires clause is not broken
4450
DLIB_ASSERT(idx < num_parts(),
45-
"\t point full_object_detection::part()"
51+
"\t dpoint full_object_detection::part()"
4652
<< "\n\t Invalid inputs were given to this function "
4753
<< "\n\t idx: " << idx
4854
<< "\n\t num_parts(): " << num_parts()
@@ -51,13 +57,13 @@ namespace dlib
5157
return parts[idx];
5258
}
5359

54-
point& part(
60+
dpoint& part(
5561
unsigned long idx
5662
)
5763
{
5864
// make sure requires clause is not broken
5965
DLIB_ASSERT(idx < num_parts(),
60-
"\t point full_object_detection::part()"
66+
"\t dpoint full_object_detection::part()"
6167
<< "\n\t Invalid inputs were given to this function "
6268
<< "\n\t idx: " << idx
6369
<< "\n\t num_parts(): " << num_parts()
@@ -71,7 +77,7 @@ namespace dlib
7177
std::ostream& out
7278
)
7379
{
74-
int version = 1;
80+
int version = 2;
7581
serialize(version, out);
7682
serialize(item.rect, out);
7783
serialize(item.parts, out);
@@ -84,11 +90,23 @@ namespace dlib
8490
{
8591
int version = 0;
8692
deserialize(version, in);
87-
if (version != 1)
93+
94+
if (version != 1 && version != 2)
8895
throw serialization_error("Unexpected version encountered while deserializing dlib::full_object_detection.");
8996

9097
deserialize(item.rect, in);
91-
deserialize(item.parts, in);
98+
99+
// Legacy support: read vector<point, 2> and cast to vector<dpoint, 2>
100+
if (version == 1) {
101+
std::vector<point> legacy_parts;
102+
deserialize(legacy_parts, in);
103+
item.parts = std::vector<dpoint>(legacy_parts.begin(), legacy_parts.end());
104+
}
105+
106+
else { // version 2 - deserialize into vector<dpoint, 2>
107+
deserialize(item.parts, in);
108+
}
109+
92110
}
93111

94112
bool operator==(
@@ -109,7 +127,7 @@ namespace dlib
109127

110128
private:
111129
rectangle rect;
112-
std::vector<point> parts;
130+
std::vector<dpoint> parts;
113131
};
114132

115133
// ----------------------------------------------------------------------------------------

dlib/image_processing/full_object_detection_abstract.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace dlib
1111
{
1212

1313
// ----------------------------------------------------------------------------------------
14-
15-
const static point OBJECT_PART_NOT_PRESENT(0x7FFFFFFF,
16-
0x7FFFFFFF);
14+
15+
const static dpoint OBJECT_PART_NOT_PRESENT(0x7FFFFFFFFFFFF,
16+
0x7FFFFFFFFFFFF);
1717

1818
// ----------------------------------------------------------------------------------------
1919

@@ -29,7 +29,7 @@ namespace dlib
2929

3030
full_object_detection(
3131
const rectangle& rect,
32-
const std::vector<point>& parts
32+
const std::vector<dpoint>& parts
3333
);
3434
/*!
3535
ensures
@@ -39,6 +39,16 @@ namespace dlib
3939
- part(i) == parts[i]
4040
!*/
4141

42+
full_object_detection(
43+
const rectangle& rect_,
44+
const std::vector<point>& parts_
45+
);
46+
/*!
47+
ensures
48+
- #get_rect() == rect
49+
- #num_parts() == parts.size()
50+
!*/
51+
4252
full_object_detection(
4353
);
4454
/*!
@@ -79,7 +89,7 @@ namespace dlib
7989
- returns the number of parts in this object.
8090
!*/
8191

82-
const point& part(
92+
const dpoint& part(
8393
unsigned long idx
8494
) const;
8595
/*!
@@ -92,7 +102,7 @@ namespace dlib
92102
This is useful for modeling object parts that are not always observed.
93103
!*/
94104

95-
point& part(
105+
dpoint& part(
96106
unsigned long idx
97107
);
98108
/*!

dlib/image_processing/scan_image_pyramid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ namespace dlib
874874
// convert into feature space.
875875
object_box = object_box.intersect(get_rect(feats[best_level]));
876876

877-
std::vector<point> movable_parts;
877+
std::vector<dpoint> movable_parts;
878878
movable_parts.reserve(get_num_movable_components_per_detection_template());
879879
for (unsigned long i = 0; i < get_num_movable_components_per_detection_template(); ++i)
880880
{

dlib/image_transforms/interpolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ namespace dlib
11251125
const full_object_detection& obj
11261126
)
11271127
{
1128-
std::vector<point> parts;
1128+
std::vector<dpoint> parts;
11291129
parts.reserve(obj.num_parts());
11301130
for (unsigned long i = 0; i < obj.num_parts(); ++i)
11311131
{

dlib/test/object_detector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ namespace
296296
std::vector<full_object_detection> temp;
297297

298298
rectangle rect = centered_rect(point(100,100), 70,71);
299-
std::vector<point> movable_parts;
299+
std::vector<dpoint> movable_parts;
300300
movable_parts.push_back(shrink_rect(rect,shrink).tl_corner());
301301
movable_parts.push_back(shrink_rect(rect,shrink).tr_corner());
302302
movable_parts.push_back(shrink_rect(rect,shrink).bl_corner());

0 commit comments

Comments
 (0)