added buffered version of norm, updated performance sample and docs

This commit is contained in:
Alexey Spizhevoy 2011-02-01 10:46:19 +00:00
parent 3795142604
commit 16e74ab306
4 changed files with 32 additions and 11 deletions

View File

@ -17,12 +17,19 @@ See also: \cvCppCross{meanStdDev}.
\cvCppFunc{gpu::norm} \cvCppFunc{gpu::norm}
Returns norm of matrix (or of two matrices difference). 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} \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.} \cvarg{normType}{Norm type. \texttt{NORM\_L1}, \texttt{NORM\_L2} and \texttt{NORM\_INF} are supported for now.}
\end{description} \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 \cvdefCpp{double norm(const GpuMat\& src1, const GpuMat\& src2,\par
int normType=NORM\_L2);} int normType=NORM\_L2);}
\begin{description} \begin{description}

View File

@ -750,9 +750,14 @@ namespace cv
//! computes norm of array //! computes norm of array
//! supports NORM_INF, NORM_L1, NORM_L2 //! 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); 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 //! computes norm of the difference between two arrays
//! supports NORM_INF, NORM_L1, NORM_L2 //! supports NORM_INF, NORM_L1, NORM_L2
//! supports only CV_8UC1 type //! supports only CV_8UC1 type

View File

@ -49,6 +49,7 @@ using namespace cv::gpu;
void cv::gpu::meanStdDev(const GpuMat&, Scalar&, Scalar&) { throw_nogpu(); } 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) { 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; } 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&) { throw_nogpu(); return Scalar(); }
Scalar cv::gpu::sum(const GpuMat&, 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 // norm
double cv::gpu::norm(const GpuMat& src, int normType) 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); GpuMat src_single_channel = src.reshape(1);
if (normType == NORM_L1) if (normType == NORM_L1)
return absSum(src_single_channel)[0]; return absSum(src_single_channel, buf)[0];
if (normType == NORM_L2) if (normType == NORM_L2)
return sqrt(sqrSum(src_single_channel)[0]); return sqrt(sqrSum(src_single_channel, buf)[0]);
if (normType == NORM_INF) if (normType == NORM_INF)
{ {
double min_val, max_val; 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)); return std::max(std::abs(min_val), std::abs(max_val));
} }

View File

@ -198,22 +198,24 @@ TEST(integral)
TEST(norm) TEST(norm)
{ {
Mat src; Mat src;
gpu::GpuMat d_src; gpu::GpuMat d_src, d_buf;
for (int size = 1000; size <= 8000; size *= 2) 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; CPU_ON;
norm(src); for (int i = 0; i < 10; ++i)
norm(src, NORM_L2);
CPU_OFF; CPU_OFF;
d_src = src; d_src = src;
GPU_ON; GPU_ON;
gpu::norm(d_src); for (int i = 0; i < 10; ++i)
gpu::norm(d_src, NORM_L2, d_buf);
GPU_OFF; GPU_OFF;
} }
} }