mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added a version of setup_hashed_features() for scan_image_boxes objects.
This commit is contained in:
parent
cd83f1cb6e
commit
b95b2e14f9
@ -24,6 +24,10 @@ namespace dlib
|
||||
): error(a) {}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// stuff for scan_image_pyramid
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
@ -95,6 +99,79 @@ namespace dlib
|
||||
setup_hashed_features(scanner, images, fe, bits, num_samples);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// stuff for scan_image_boxes
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename image_array,
|
||||
typename feature_extractor
|
||||
>
|
||||
void setup_hashed_features (
|
||||
scan_image_boxes<hashed_feature_image<feature_extractor, projection_hash> >& scanner,
|
||||
const image_array& images,
|
||||
const feature_extractor& fe,
|
||||
int bits,
|
||||
unsigned long num_samples = 200000
|
||||
)
|
||||
{
|
||||
// make sure requires clause is not broken
|
||||
DLIB_ASSERT(0 < bits && bits <= 32 &&
|
||||
num_samples > 1 &&
|
||||
images.size() > 0,
|
||||
"\t void setup_hashed_features()"
|
||||
<< "\n\t Invalid inputs were given to this function. "
|
||||
<< "\n\t bits: " << bits
|
||||
<< "\n\t num_samples: " << num_samples
|
||||
<< "\n\t images.size(): " << images.size()
|
||||
);
|
||||
|
||||
pyramid_disable pyr;
|
||||
|
||||
const random_subset_selector<typename feature_extractor::descriptor_type>& samps =
|
||||
randomly_sample_image_features(images, pyr, fe, num_samples);
|
||||
|
||||
if (samps.size() <= 1)
|
||||
throw dlib::image_hash_construction_failure("Images too small, not able to gather enough samples to make hash");
|
||||
|
||||
projection_hash phash = create_random_projection_hash(samps, bits);
|
||||
|
||||
hashed_feature_image<feature_extractor, projection_hash> hfe;
|
||||
hfe.set_hash(phash);
|
||||
hfe.copy_configuration(fe);
|
||||
scanner.copy_configuration(hfe);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename image_array,
|
||||
typename feature_extractor
|
||||
>
|
||||
void setup_hashed_features (
|
||||
scan_image_boxes<hashed_feature_image<feature_extractor, projection_hash> >& scanner,
|
||||
const image_array& images,
|
||||
int bits,
|
||||
unsigned long num_samples = 200000
|
||||
)
|
||||
{
|
||||
// make sure requires clause is not broken
|
||||
DLIB_ASSERT(0 < bits && bits <= 32 &&
|
||||
num_samples > 1 &&
|
||||
images.size() > 0,
|
||||
"\t void setup_hashed_features()"
|
||||
<< "\n\t Invalid inputs were given to this function. "
|
||||
<< "\n\t bits: " << bits
|
||||
<< "\n\t num_samples: " << num_samples
|
||||
<< "\n\t images.size(): " << images.size()
|
||||
);
|
||||
|
||||
feature_extractor fe;
|
||||
setup_hashed_features(scanner, images, fe, bits, num_samples);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
@ -85,6 +85,71 @@ namespace dlib
|
||||
feature vectors.
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename image_array,
|
||||
typename feature_extractor
|
||||
>
|
||||
void setup_hashed_features (
|
||||
scan_image_boxes<hashed_feature_image<feature_extractor, projection_hash> >& scanner,
|
||||
const image_array& images,
|
||||
const feature_extractor& fe,
|
||||
int bits,
|
||||
unsigned long num_samples = 200000
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- 0 < bits <= 32
|
||||
- num_samples > 1
|
||||
- images.size() > 0
|
||||
- it must be valid to pass images[0] into scanner.load().
|
||||
(also, image_array must be an implementation of dlib/array/array_kernel_abstract.h)
|
||||
ensures
|
||||
- Creates a projection_hash suitable for hashing the feature vectors produced by
|
||||
fe and then configures scanner to use this hash function.
|
||||
- The hash function will map vectors into integers in the range [0, pow(2,bits))
|
||||
- The hash function will be setup so that it hashes a random sample of num_samples
|
||||
vectors from fe such that each bin ends up with roughly the same number of
|
||||
elements in it.
|
||||
throws
|
||||
- image_hash_construction_failure
|
||||
This exception is thrown if there is a problem creating the projection_hash.
|
||||
This should only happen the images are so small they contain less than 2
|
||||
feature vectors.
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <
|
||||
typename image_array,
|
||||
typename feature_extractor
|
||||
>
|
||||
void setup_hashed_features (
|
||||
scan_image_boxes<hashed_feature_image<feature_extractor, projection_hash> >& scanner,
|
||||
const image_array& images,
|
||||
int bits,
|
||||
unsigned long num_samples = 200000
|
||||
);
|
||||
/*!
|
||||
requires
|
||||
- 0 < bits <= 32
|
||||
- num_samples > 1
|
||||
- images.size() > 0
|
||||
- it must be valid to pass images[0] into scanner.load().
|
||||
(also, image_array must be an implementation of dlib/array/array_kernel_abstract.h)
|
||||
ensures
|
||||
- performs: setup_hashed_features(scanner, images, feature_extractor(), bits, num_samples)
|
||||
throws
|
||||
- image_hash_construction_failure
|
||||
This exception is thrown if there is a problem creating the projection_hash.
|
||||
This should only happen the images are so small they contain less than 2
|
||||
feature vectors.
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user