Commit 2384f6cc authored by Davis King's avatar Davis King

Added missing asserts

parent 17a46669
...@@ -49,6 +49,15 @@ namespace dlib ...@@ -49,6 +49,15 @@ namespace dlib
unsigned long height unsigned long height
) )
{ {
// make sure requires clause is not broken
DLIB_ASSERT(width > 0 && height > 0,
"\t void scan_fhog_pyramid::set_detection_window_size()"
<< "\n\t Invalid inputs were given to this function "
<< "\n\t width: " << width
<< "\n\t height: " << height
<< "\n\t this: " << this
);
window_width = width; window_width = width;
window_height = height; window_height = height;
} }
...@@ -118,6 +127,17 @@ namespace dlib ...@@ -118,6 +127,17 @@ namespace dlib
const double thresh const double thresh
) const ) const
{ {
// make sure requires clause is not broken
DLIB_ASSERT(is_loaded_with_image() &&
w.size() >= get_num_dimensions(),
"\t void scan_fhog_pyramid::detect()"
<< "\n\t Invalid inputs were given to this function "
<< "\n\t is_loaded_with_image(): " << is_loaded_with_image()
<< "\n\t w.size(): " << w.size()
<< "\n\t get_num_dimensions(): " << get_num_dimensions()
<< "\n\t this: " << this
);
fhog_filterbank temp = build_fhog_filterbank(w); fhog_filterbank temp = build_fhog_filterbank(w);
detect(temp, dets, thresh); detect(temp, dets, thresh);
} }
...@@ -157,6 +177,15 @@ namespace dlib ...@@ -157,6 +177,15 @@ namespace dlib
const feature_vector_type& weights const feature_vector_type& weights
) const ) const
{ {
// make sure requires clause is not broken
DLIB_ASSERT(weights.size() >= get_num_dimensions(),
"\t fhog_filterbank scan_fhog_pyramid::build_fhog_filterbank()"
<< "\n\t The number of weights isn't enough to fill out the filterbank. "
<< "\n\t weights.size(): " << weights.size()
<< "\n\t get_num_dimensions(): " << get_num_dimensions()
<< "\n\t this: " << this
);
fhog_filterbank temp; fhog_filterbank temp;
temp.filters.resize(31); temp.filters.resize(31);
temp.row_filters.resize(31); temp.row_filters.resize(31);
...@@ -222,13 +251,15 @@ namespace dlib ...@@ -222,13 +251,15 @@ namespace dlib
void set_nuclear_norm_regularization_strength ( void set_nuclear_norm_regularization_strength (
double strength double strength
) )
/*!
requires
- strength >= 0
ensures
- #get_nuclear_norm_regularization_strength() == strength
!*/
{ {
// make sure requires clause is not broken
DLIB_ASSERT(strength >= 0 ,
"\t void scan_fhog_pyramid::set_nuclear_norm_regularization_strength()"
<< "\n\t You can't have a negative regularization strength."
<< "\n\t strength: " << strength
<< "\n\t this: " << this
);
nuclear_norm_regularization_strength = strength; nuclear_norm_regularization_strength = strength;
} }
...@@ -836,6 +867,15 @@ namespace dlib ...@@ -836,6 +867,15 @@ namespace dlib
const long cell_draw_size = 15 const long cell_draw_size = 15
) )
{ {
// make sure requires clause is not broken
DLIB_ASSERT(cell_draw_size > 0 && detector.get_w().size() >= detector.get_scanner().get_num_dimensions() ,
"\t matrix draw_fhog()"
<< "\n\t Invalid arguments were given to this function. "
<< "\n\t cell_draw_size: " << cell_draw_size
<< "\n\t detector.get_w().size(): " << detector.get_w().size()
<< "\n\t detector.get_scanner().get_num_dimensions(): " << detector.get_scanner().get_num_dimensions()
);
typename scan_fhog_pyramid<Pyramid_type>::fhog_filterbank fb = detector.get_scanner().build_fhog_filterbank(detector.get_w()); typename scan_fhog_pyramid<Pyramid_type>::fhog_filterbank fb = detector.get_scanner().build_fhog_filterbank(detector.get_w());
return draw_fhog(fb.get_filters(),cell_draw_size); return draw_fhog(fb.get_filters(),cell_draw_size);
} }
...@@ -849,6 +889,14 @@ namespace dlib ...@@ -849,6 +889,14 @@ namespace dlib
const object_detector<scan_fhog_pyramid<Pyramid_type> >& detector const object_detector<scan_fhog_pyramid<Pyramid_type> >& detector
) )
{ {
// make sure requires clause is not broken
DLIB_ASSERT(detector.get_w().size() >= detector.get_scanner().get_num_dimensions() ,
"\t unsigned long num_separable_filters()"
<< "\n\t Invalid arguments were given to this function. "
<< "\n\t detector.get_w().size(): " << detector.get_w().size()
<< "\n\t detector.get_scanner().get_num_dimensions(): " << detector.get_scanner().get_num_dimensions()
);
typename scan_fhog_pyramid<Pyramid_type>::fhog_filterbank fb = detector.get_scanner().build_fhog_filterbank(detector.get_w()); typename scan_fhog_pyramid<Pyramid_type>::fhog_filterbank fb = detector.get_scanner().build_fhog_filterbank(detector.get_w());
return fb.num_separable_filters(); return fb.num_separable_filters();
} }
......
...@@ -416,7 +416,7 @@ namespace dlib ...@@ -416,7 +416,7 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- w.get_num_dimensions() >= get_num_dimensions() - w.size() >= get_num_dimensions()
- is_loaded_with_image() == true - is_loaded_with_image() == true
ensures ensures
- performs: detect(build_fhog_filterbank(w), dets, thresh) - performs: detect(build_fhog_filterbank(w), dets, thresh)
......
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