Commit 0bdcb98c authored by Davis King's avatar Davis King

Fixed a bug in extract_fhog_features() that happened when very small

images were given.
parent e0a6e305
...@@ -193,6 +193,12 @@ namespace dlib ...@@ -193,6 +193,12 @@ namespace dlib
const int cells_nr = (int)((double)img.nr()/(double)cell_size + 0.5); const int cells_nr = (int)((double)img.nr()/(double)cell_size + 0.5);
const int cells_nc = (int)((double)img.nc()/(double)cell_size + 0.5); const int cells_nc = (int)((double)img.nc()/(double)cell_size + 0.5);
if (cells_nr == 0 || cells_nc == 0)
{
hog.clear();
return;
}
array2d<matrix<float,18,1> > hist(cells_nr, cells_nc); array2d<matrix<float,18,1> > hist(cells_nr, cells_nc);
for (long r = 0; r < hist.nr(); ++r) for (long r = 0; r < hist.nr(); ++r)
{ {
...@@ -208,6 +214,11 @@ namespace dlib ...@@ -208,6 +214,11 @@ namespace dlib
// memory for HOG features // memory for HOG features
const int hog_nr = std::max(cells_nr-2, 0); const int hog_nr = std::max(cells_nr-2, 0);
const int hog_nc = std::max(cells_nc-2, 0); const int hog_nc = std::max(cells_nc-2, 0);
if (hog_nr == 0 || hog_nc == 0)
{
hog.clear();
return;
}
init_hog(hog, hog_nr, hog_nc); init_hog(hog, hog_nr, hog_nc);
const int visible_nr = cells_nr*cell_size; const int visible_nr = cells_nr*cell_size;
......
...@@ -76,9 +76,38 @@ namespace ...@@ -76,9 +76,38 @@ namespace
} }
} }
void test_on_small()
{
print_spinner();
array2d<unsigned char> img;
dlib::array<array2d<float> > hog;
// do this just to make sure it doesn't crash on small images
for (int i = 0; i < 10; ++i)
{
img.set_size(i,i);
assign_all_pixels(img, i);
extract_fhog_features(img, hog);
}
for (int i = 1; i < 10; ++i)
{
img.set_size(i,i+1);
assign_all_pixels(img, i);
extract_fhog_features(img, hog);
}
for (int i = 1; i < 10; ++i)
{
img.set_size(i+1,i);
assign_all_pixels(img, i);
extract_fhog_features(img, hog);
}
}
void perform_test ( void perform_test (
) )
{ {
test_on_small();
print_spinner(); print_spinner();
// load the testing data // load the testing data
array2d<rgb_pixel> img; array2d<rgb_pixel> img;
......
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