Merge remote-tracking branch 'origin/2.4' into merge-2.4
Conflicts: modules/calib3d/include/opencv2/calib3d/calib3d.hpp modules/contrib/doc/facerec/facerec_api.rst modules/contrib/include/opencv2/contrib/contrib.hpp modules/contrib/src/facerec.cpp modules/core/include/opencv2/core/mat.hpp modules/features2d/include/opencv2/features2d/features2d.hpp modules/highgui/src/loadsave.cpp modules/imgproc/src/pyramids.cpp modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp modules/python/src2/gen.py modules/python/test/test.py modules/superres/test/test_superres.cpp samples/cpp/facerec_demo.cpp
This commit is contained in:
@@ -837,6 +837,66 @@ typename Distance::ResultType ensureSquareDistance( typename Distance::ResultTyp
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ...and a template to ensure the user that he will process the normal distance,
|
||||
* and not squared distance, without loosing processing time calling sqrt(ensureSquareDistance)
|
||||
* that will result in doing actually sqrt(dist*dist) for L1 distance for instance.
|
||||
*/
|
||||
template <typename Distance, typename ElementType>
|
||||
struct simpleDistance
|
||||
{
|
||||
typedef typename Distance::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2_Simple<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2_Simple<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<MinkowskiDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename MinkowskiDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<HellingerDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename HellingerDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<ChiSquareDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename ChiSquareDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultType dist )
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
|
||||
simpleDistance<Distance, ElementType> dummy;
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //OPENCV_FLANN_DIST_H_
|
||||
|
@@ -109,10 +109,22 @@ public:
|
||||
*/
|
||||
void buildIndex()
|
||||
{
|
||||
std::vector<size_t> indices(feature_size_ * CHAR_BIT);
|
||||
|
||||
tables_.resize(table_number_);
|
||||
for (unsigned int i = 0; i < table_number_; ++i) {
|
||||
|
||||
//re-initialize the random indices table that the LshTable will use to pick its sub-dimensions
|
||||
if( (indices.size() == feature_size_ * CHAR_BIT) || (indices.size() < key_size_) )
|
||||
{
|
||||
indices.resize( feature_size_ * CHAR_BIT );
|
||||
for (size_t j = 0; j < feature_size_ * CHAR_BIT; ++j)
|
||||
indices[j] = j;
|
||||
std::random_shuffle(indices.begin(), indices.end());
|
||||
}
|
||||
|
||||
lsh::LshTable<ElementType>& table = tables_[i];
|
||||
table = lsh::LshTable<ElementType>(feature_size_, key_size_);
|
||||
table = lsh::LshTable<ElementType>(feature_size_, key_size_, indices);
|
||||
|
||||
// Add the features to the table
|
||||
table.add(dataset_);
|
||||
|
@@ -153,7 +153,7 @@ public:
|
||||
* @param feature_size is the size of the feature (considered as a ElementType[])
|
||||
* @param key_size is the number of bits that are turned on in the feature
|
||||
*/
|
||||
LshTable(unsigned int /*feature_size*/, unsigned int /*key_size*/)
|
||||
LshTable(unsigned int /*feature_size*/, unsigned int /*key_size*/, std::vector<size_t> & /*indices*/)
|
||||
{
|
||||
std::cerr << "LSH is not implemented for that type" << std::endl;
|
||||
assert(0);
|
||||
@@ -339,20 +339,20 @@ private:
|
||||
// Specialization for unsigned char
|
||||
|
||||
template<>
|
||||
inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int subsignature_size)
|
||||
inline LshTable<unsigned char>::LshTable( unsigned int feature_size,
|
||||
unsigned int subsignature_size,
|
||||
std::vector<size_t> & indices )
|
||||
{
|
||||
initialize(subsignature_size);
|
||||
// Allocate the mask
|
||||
mask_ = std::vector<size_t>((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0);
|
||||
|
||||
// A bit brutal but fast to code
|
||||
std::vector<size_t> indices(feature_size * CHAR_BIT);
|
||||
for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i;
|
||||
std::random_shuffle(indices.begin(), indices.end());
|
||||
|
||||
// Generate a random set of order of subsignature_size_ bits
|
||||
for (unsigned int i = 0; i < key_size_; ++i) {
|
||||
size_t index = indices[i];
|
||||
//Ensure the Nth bit will be selected only once among the different LshTables
|
||||
//to avoid having two different tables with signatures sharing many dimensions/many bits
|
||||
size_t index = indices[0];
|
||||
indices.erase( indices.begin() );
|
||||
|
||||
// Set that bit in the mask
|
||||
size_t divisor = CHAR_BIT * sizeof(size_t);
|
||||
|
Reference in New Issue
Block a user