mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 19:20:28 +08:00
added buffered version of norm, updated performance sample and docs
This commit is contained in:
parent
3795142604
commit
16e74ab306
@ -17,12 +17,19 @@ See also: \cvCppCross{meanStdDev}.
|
||||
\cvCppFunc{gpu::norm}
|
||||
Returns norm of matrix (or of two matrices difference).
|
||||
|
||||
\cvdefCpp{double norm(const GpuMat\& src1, int normType=NORM\_L2);}
|
||||
\cvdefCpp{double norm(const GpuMat\& src, int normType=NORM\_L2);}
|
||||
\begin{description}
|
||||
\cvarg{src1}{Source matrix. Any matrices except 64F are supported.}
|
||||
\cvarg{src}{Source matrix. Any matrices except 64F are supported.}
|
||||
\cvarg{normType}{Norm type. \texttt{NORM\_L1}, \texttt{NORM\_L2} and \texttt{NORM\_INF} are supported for now.}
|
||||
\end{description}
|
||||
|
||||
\cvdefCpp{double norm(const GpuMat\& src, int normType, GpuMat\& buf);}
|
||||
\begin{description}
|
||||
\cvarg{src}{Source matrix. Any matrices except 64F are supported.}
|
||||
\cvarg{normType}{Norm type. \texttt{NORM\_L1}, \texttt{NORM\_L2} and \texttt{NORM\_INF} are supported for now.}
|
||||
\cvarg{buf}{Optional buffer to avoid extra memory allocations. It's resized automatically.}
|
||||
\end{description}
|
||||
|
||||
\cvdefCpp{double norm(const GpuMat\& src1, const GpuMat\& src2,\par
|
||||
int normType=NORM\_L2);}
|
||||
\begin{description}
|
||||
|
@ -750,9 +750,14 @@ namespace cv
|
||||
|
||||
//! computes norm of array
|
||||
//! supports NORM_INF, NORM_L1, NORM_L2
|
||||
//! supports only CV_8UC1 type
|
||||
//! supports all matrices except 64F
|
||||
CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
|
||||
|
||||
//! computes norm of array
|
||||
//! supports NORM_INF, NORM_L1, NORM_L2
|
||||
//! supports all matrices except 64F
|
||||
CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);
|
||||
|
||||
//! computes norm of the difference between two arrays
|
||||
//! supports NORM_INF, NORM_L1, NORM_L2
|
||||
//! supports only CV_8UC1 type
|
||||
|
@ -49,6 +49,7 @@ using namespace cv::gpu;
|
||||
|
||||
void cv::gpu::meanStdDev(const GpuMat&, Scalar&, Scalar&) { throw_nogpu(); }
|
||||
double cv::gpu::norm(const GpuMat&, int) { throw_nogpu(); return 0.0; }
|
||||
double cv::gpu::norm(const GpuMat&, int, GpuMat&) { throw_nogpu(); return 0.0; }
|
||||
double cv::gpu::norm(const GpuMat&, const GpuMat&, int) { throw_nogpu(); return 0.0; }
|
||||
Scalar cv::gpu::sum(const GpuMat&) { throw_nogpu(); return Scalar(); }
|
||||
Scalar cv::gpu::sum(const GpuMat&, GpuMat&) { throw_nogpu(); return Scalar(); }
|
||||
@ -87,19 +88,25 @@ void cv::gpu::meanStdDev(const GpuMat& src, Scalar& mean, Scalar& stddev)
|
||||
// norm
|
||||
|
||||
double cv::gpu::norm(const GpuMat& src, int normType)
|
||||
{
|
||||
GpuMat buf;
|
||||
return norm(src, normType, buf);
|
||||
}
|
||||
|
||||
double cv::gpu::norm(const GpuMat& src, int normType, GpuMat& buf)
|
||||
{
|
||||
GpuMat src_single_channel = src.reshape(1);
|
||||
|
||||
if (normType == NORM_L1)
|
||||
return absSum(src_single_channel)[0];
|
||||
return absSum(src_single_channel, buf)[0];
|
||||
|
||||
if (normType == NORM_L2)
|
||||
return sqrt(sqrSum(src_single_channel)[0]);
|
||||
return sqrt(sqrSum(src_single_channel, buf)[0]);
|
||||
|
||||
if (normType == NORM_INF)
|
||||
{
|
||||
double min_val, max_val;
|
||||
minMax(src_single_channel, &min_val, &max_val);
|
||||
minMax(src_single_channel, &min_val, &max_val, GpuMat(), buf);
|
||||
return std::max(std::abs(min_val), std::abs(max_val));
|
||||
}
|
||||
|
||||
|
@ -198,22 +198,24 @@ TEST(integral)
|
||||
TEST(norm)
|
||||
{
|
||||
Mat src;
|
||||
gpu::GpuMat d_src;
|
||||
gpu::GpuMat d_src, d_buf;
|
||||
|
||||
for (int size = 1000; size <= 8000; size *= 2)
|
||||
{
|
||||
SUBTEST << "size " << size << ", 8U";
|
||||
SUBTEST << "size " << size << ", 32F";
|
||||
|
||||
gen(src, size, size, CV_8U, 0, 256);
|
||||
gen(src, size, size, CV_32F, 0, 1);
|
||||
|
||||
CPU_ON;
|
||||
norm(src);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
norm(src, NORM_L2);
|
||||
CPU_OFF;
|
||||
|
||||
d_src = src;
|
||||
|
||||
GPU_ON;
|
||||
gpu::norm(d_src);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
gpu::norm(d_src, NORM_L2, d_buf);
|
||||
GPU_OFF;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user