diff --git a/dlib/data_io/load_image_dataset.h b/dlib/data_io/load_image_dataset.h index 5664d96b2e..2912f817fe 100644 --- a/dlib/data_io/load_image_dataset.h +++ b/dlib/data_io/load_image_dataset.h @@ -406,7 +406,7 @@ namespace dlib } else { - std::vector partlist(parts_idx.size(), OBJECT_PART_NOT_PRESENT); + std::vector partlist(parts_idx.size(), OBJECT_PART_NOT_PRESENT); // populate partlist with all the parts present in this box. const std::map& parts = data.images[i].boxes[j].parts; diff --git a/dlib/image_processing/full_object_detection.h b/dlib/image_processing/full_object_detection.h index 5c6d112dfa..dc4721b108 100644 --- a/dlib/image_processing/full_object_detection.h +++ b/dlib/image_processing/full_object_detection.h @@ -13,8 +13,8 @@ namespace dlib // ---------------------------------------------------------------------------------------- - const static point OBJECT_PART_NOT_PRESENT(0x7FFFFFFF, - 0x7FFFFFFF); + const static dpoint OBJECT_PART_NOT_PRESENT(0x7FFFFFFFFFFFF, + 0x7FFFFFFFFFFFF); // ---------------------------------------------------------------------------------------- @@ -23,9 +23,15 @@ namespace dlib public: full_object_detection( const rectangle& rect_, - const std::vector& parts_ + const std::vector& parts_ ) : rect(rect_), parts(parts_) {} + full_object_detection( + const rectangle& rect_, + const std::vector& parts_ + ) : rect(rect_), parts (parts_.begin(), parts_.end()) + {} + full_object_detection(){} explicit full_object_detection( @@ -36,13 +42,13 @@ namespace dlib rectangle& get_rect() { return rect; } unsigned long num_parts() const { return parts.size(); } - const point& part( + const dpoint& part( unsigned long idx ) const { // make sure requires clause is not broken DLIB_ASSERT(idx < num_parts(), - "\t point full_object_detection::part()" + "\t dpoint full_object_detection::part()" << "\n\t Invalid inputs were given to this function " << "\n\t idx: " << idx << "\n\t num_parts(): " << num_parts() @@ -51,13 +57,13 @@ namespace dlib return parts[idx]; } - point& part( + dpoint& part( unsigned long idx ) { // make sure requires clause is not broken DLIB_ASSERT(idx < num_parts(), - "\t point full_object_detection::part()" + "\t dpoint full_object_detection::part()" << "\n\t Invalid inputs were given to this function " << "\n\t idx: " << idx << "\n\t num_parts(): " << num_parts() @@ -71,7 +77,7 @@ namespace dlib std::ostream& out ) { - int version = 1; + int version = 2; serialize(version, out); serialize(item.rect, out); serialize(item.parts, out); @@ -84,11 +90,23 @@ namespace dlib { int version = 0; deserialize(version, in); - if (version != 1) + + if (version != 1 && version != 2) throw serialization_error("Unexpected version encountered while deserializing dlib::full_object_detection."); deserialize(item.rect, in); - deserialize(item.parts, in); + + // Legacy support: read vector and cast to vector + if (version == 1) { + std::vector legacy_parts; + deserialize(legacy_parts, in); + item.parts = std::vector(legacy_parts.begin(), legacy_parts.end()); + } + + else { // version 2 - deserialize into vector + deserialize(item.parts, in); + } + } bool operator==( @@ -109,7 +127,7 @@ namespace dlib private: rectangle rect; - std::vector parts; + std::vector parts; }; // ---------------------------------------------------------------------------------------- diff --git a/dlib/image_processing/full_object_detection_abstract.h b/dlib/image_processing/full_object_detection_abstract.h index 1f71413d4a..6d08020c83 100644 --- a/dlib/image_processing/full_object_detection_abstract.h +++ b/dlib/image_processing/full_object_detection_abstract.h @@ -11,9 +11,9 @@ namespace dlib { // ---------------------------------------------------------------------------------------- - - const static point OBJECT_PART_NOT_PRESENT(0x7FFFFFFF, - 0x7FFFFFFF); + + const static dpoint OBJECT_PART_NOT_PRESENT(0x7FFFFFFFFFFFF, + 0x7FFFFFFFFFFFF); // ---------------------------------------------------------------------------------------- @@ -29,7 +29,7 @@ namespace dlib full_object_detection( const rectangle& rect, - const std::vector& parts + const std::vector& parts ); /*! ensures @@ -39,6 +39,16 @@ namespace dlib - part(i) == parts[i] !*/ + full_object_detection( + const rectangle& rect_, + const std::vector& parts_ + ); + /*! + ensures + - #get_rect() == rect + - #num_parts() == parts.size() + !*/ + full_object_detection( ); /*! @@ -79,7 +89,7 @@ namespace dlib - returns the number of parts in this object. !*/ - const point& part( + const dpoint& part( unsigned long idx ) const; /*! @@ -92,7 +102,7 @@ namespace dlib This is useful for modeling object parts that are not always observed. !*/ - point& part( + dpoint& part( unsigned long idx ); /*! diff --git a/dlib/image_processing/scan_image_pyramid.h b/dlib/image_processing/scan_image_pyramid.h index 455f1a649c..1ce7c69cbe 100644 --- a/dlib/image_processing/scan_image_pyramid.h +++ b/dlib/image_processing/scan_image_pyramid.h @@ -874,7 +874,7 @@ namespace dlib // convert into feature space. object_box = object_box.intersect(get_rect(feats[best_level])); - std::vector movable_parts; + std::vector movable_parts; movable_parts.reserve(get_num_movable_components_per_detection_template()); for (unsigned long i = 0; i < get_num_movable_components_per_detection_template(); ++i) { diff --git a/dlib/image_transforms/interpolation.h b/dlib/image_transforms/interpolation.h index 51e8168f85..750c05547c 100644 --- a/dlib/image_transforms/interpolation.h +++ b/dlib/image_transforms/interpolation.h @@ -1125,7 +1125,7 @@ namespace dlib const full_object_detection& obj ) { - std::vector parts; + std::vector parts; parts.reserve(obj.num_parts()); for (unsigned long i = 0; i < obj.num_parts(); ++i) { diff --git a/dlib/test/object_detector.cpp b/dlib/test/object_detector.cpp index fdb72f5207..b7f630597c 100644 --- a/dlib/test/object_detector.cpp +++ b/dlib/test/object_detector.cpp @@ -296,7 +296,7 @@ namespace std::vector temp; rectangle rect = centered_rect(point(100,100), 70,71); - std::vector movable_parts; + std::vector movable_parts; movable_parts.push_back(shrink_rect(rect,shrink).tl_corner()); movable_parts.push_back(shrink_rect(rect,shrink).tr_corner()); movable_parts.push_back(shrink_rect(rect,shrink).bl_corner());