1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Replace naive normL2Sqr with hal::normL2Sqr_ for better performance

This commit is contained in:
woody.chow
2018-09-06 17:43:07 +09:00
parent 8e8315abfd
commit 07c6b0a8df
2 changed files with 43 additions and 5 deletions
+37
View File
@@ -5,6 +5,7 @@
#include "precomp.hpp"
#include "stat.hpp"
#include <opencv2/core/hal/hal.hpp>
namespace cv
{
@@ -45,6 +46,24 @@ void batchDistL2Sqr_(const _Tp* src1, const _Tp* src2, size_t step2,
}
}
template<>
void batchDistL2Sqr_(const float* src1, const float* src2, size_t step2,
int nvecs, int len, float* dist, const uchar* mask)
{
step2 /= sizeof(src2[0]);
if( !mask )
{
for( int i = 0; i < nvecs; i++ )
dist[i] = hal::normL2Sqr_(src1, src2 + step2*i, len);
}
else
{
float val0 = std::numeric_limits<float>::max();
for( int i = 0; i < nvecs; i++ )
dist[i] = mask[i] ? hal::normL2Sqr_(src1, src2 + step2*i, len) : val0;
}
}
template<typename _Tp, typename _Rt>
void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2,
int nvecs, int len, _Rt* dist, const uchar* mask)
@@ -63,6 +82,24 @@ void batchDistL2_(const _Tp* src1, const _Tp* src2, size_t step2,
}
}
template<>
void batchDistL2_(const float* src1, const float* src2, size_t step2,
int nvecs, int len, float* dist, const uchar* mask)
{
step2 /= sizeof(src2[0]);
if( !mask )
{
for( int i = 0; i < nvecs; i++ )
dist[i] = std::sqrt(hal::normL2Sqr_(src1, src2 + step2*i, len));
}
else
{
float val0 = std::numeric_limits<float>::max();
for( int i = 0; i < nvecs; i++ )
dist[i] = mask[i] ? std::sqrt(hal::normL2Sqr_(src1, src2 + step2*i, len)) : val0;
}
}
static void batchDistHamming(const uchar* src1, const uchar* src2, size_t step2,
int nvecs, int len, int* dist, const uchar* mask)
{