MCPcopy Create free account
hub / github.com/davisking/dlib / test_extract_image_chips

Function test_extract_image_chips

dlib/test/image.cpp:1996–2092  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1994// ----------------------------------------------------------------------------------------
1995
1996 void test_extract_image_chips()
1997 {
1998 dlib::rand rnd;
1999
2000 // Make sure that cropping a white box out of a larger white image always produces an
2001 // exact white box. This should catch any bad border effects from a messed up internal
2002 // cropping.
2003 for (int iter = 0; iter < 1000; ++iter)
2004 {
2005 print_spinner();
2006 const long nr = rnd.get_random_32bit_number()%100 + 1;
2007 const long nc = rnd.get_random_32bit_number()%100 + 1;
2008 const long size = rnd.get_random_32bit_number()%10000 + 4;
2009 const double angle = rnd.get_random_double() * pi;
2010
2011 matrix<int> img(501,501), chip;
2012 img = 255;
2013 chip_details details(centered_rect(center(get_rect(img)),nr,nc), size, angle);
2014 extract_image_chip(img, details, chip);
2015 DLIB_TEST_MSG(max(abs(chip-255))==0,"nr: " << nr << " nc: "<< nc << " size: " << size << " angle: " << angle
2016 << " error: " << max(abs(chip-255)) );
2017 }
2018
2019 // So the same as above, but for an image with float values that are all the same to make
2020 // sure noting funny happens for float images.
2021 {
2022 print_spinner();
2023 const long nr = 53;
2024 const long nc = 67;
2025 const long size = 8*9;
2026 const double angle = 30*pi/180;
2027
2028 matrix<float> img(501,501), chip;
2029 img = 1234.5;
2030 chip_details details(centered_rect(center(get_rect(img)),nr,nc), size, angle);
2031 extract_image_chip(img, details, chip);
2032 DLIB_TEST_MSG(max(abs(chip-1234.5))==0,"nr: " << nr << " nc: "<< nc << " size: " << size << " angle: " << angle
2033 << " error: " << max(abs(chip-255)) );
2034 }
2035
2036
2037 {
2038 // Make sure that the interpolation in extract_image_chip() keeps stuff in the
2039 // right places.
2040
2041 matrix<unsigned char> img(10,10), chip;
2042 img = 0;
2043 img(1,1) = 255;
2044 img(8,8) = 255;
2045
2046 extract_image_chip(img, chip_details(get_rect(img), 9*9), chip);
2047
2048 DLIB_TEST(chip(1,1) == 195);
2049 DLIB_TEST(chip(7,7) == 195);
2050 chip(1,1) -= 195;
2051 chip(7,7) -= 195;
2052 DLIB_TEST(sum(matrix_cast<int>(chip)) == 0);
2053 }

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
centered_rectFunction · 0.85
get_rectFunction · 0.85
extract_image_chipFunction · 0.85
absFunction · 0.85
rotate_pointFunction · 0.85
max_pointFunction · 0.85
get_random_doubleMethod · 0.80
get_lineMethod · 0.80
centerFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected