| 67 | template <typename fe, typename hash> class feature_image |
| 68 | > |
| 69 | void setup_hashed_features ( |
| 70 | scan_image_pyramid<pyramid, feature_image<feature_extractor, projection_hash> >& scanner, |
| 71 | const image_array& images, |
| 72 | const feature_extractor& fe, |
| 73 | int bits, |
| 74 | unsigned long num_samples = 200000 |
| 75 | ) |
| 76 | { |
| 77 | // make sure requires clause is not broken |
| 78 | DLIB_ASSERT(0 < bits && bits <= 32 && |
| 79 | num_samples > 1 && |
| 80 | images.size() > 0, |
| 81 | "\t void setup_hashed_features()" |
| 82 | << "\n\t Invalid inputs were given to this function. " |
| 83 | << "\n\t bits: " << bits |
| 84 | << "\n\t num_samples: " << num_samples |
| 85 | << "\n\t images.size(): " << images.size() |
| 86 | ); |
| 87 | |
| 88 | pyramid pyr; |
| 89 | |
| 90 | const random_subset_selector<typename feature_extractor::descriptor_type>& samps = |
| 91 | randomly_sample_image_features(images, pyr, fe, num_samples); |
| 92 | |
| 93 | if (samps.size() <= 1) |
| 94 | throw dlib::image_hash_construction_failure("Images too small, not able to gather enough samples to make hash"); |
| 95 | |
| 96 | projection_hash phash = create_random_projection_hash(samps, bits); |
| 97 | |
| 98 | feature_image<feature_extractor, projection_hash> hfe; |
| 99 | hfe.copy_configuration(scanner.get_feature_extractor()); |
| 100 | hfe.set_hash(phash); |
| 101 | hfe.copy_configuration(fe); |
| 102 | scanner.copy_configuration(hfe); |
| 103 | } |
| 104 | |
| 105 | // ---------------------------------------------------------------------------------------- |
| 106 | |