added ensureSizeIsEnough into gpu module, updated reduction methods
This commit is contained in:
parent
f3a2656808
commit
cbb132ccb1
@ -12,4 +12,24 @@ Creates continuous matrix in GPU memory.
|
||||
\cvarg{m}{Destination matrix. Will be only reshaped if it has proper type and area (\texttt{rows} $\times$ \texttt{cols}).}
|
||||
\end{description}
|
||||
|
||||
Matrix is called continuous if its elements are stored continuously, i.e. wuthout gaps in the end of each row.
|
||||
Also the following wrappers are available:
|
||||
\cvdefCpp{GpuMat createContinuous(int rows, int cols, int type);\newline
|
||||
void createContinuous(Size size, int type, GpuMat\& m);\newline
|
||||
GpuMat createContinuous(Size size, int type);}
|
||||
|
||||
Matrix is called continuous if its elements are stored continuously, i.e. wuthout gaps in the end of each row.
|
||||
|
||||
|
||||
\cvCppFunc{gpu::ensureSizeIsEnough}
|
||||
Ensures that size of matrix is big enough and matrix has proper type. The function doesn't reallocate memory if matrix has proper attributes already.
|
||||
|
||||
\cvdefCpp{void ensureSizeIsEnough(int rows, int cols, int type, GpuMat\& m);}
|
||||
\begin{description}
|
||||
\cvarg{rows}{Minimum desired number of rows.}
|
||||
\cvarg{cols}{Minimum desired number of cols.}
|
||||
\cvarg{type}{Desired matrix type.}
|
||||
\cvarg{m}{Destination matrix.}
|
||||
\end{description}
|
||||
|
||||
Also the following wrapper is available:
|
||||
\cvdefCpp{void ensureSizeIsEnough(Size size, int type, GpuMat\& m);}
|
@ -252,9 +252,13 @@ namespace cv
|
||||
#include "GpuMat_BetaDeprecated.hpp"
|
||||
#endif
|
||||
|
||||
//! creates continuous GPU matrix
|
||||
//! Creates continuous GPU matrix
|
||||
CV_EXPORTS void createContinuous(int rows, int cols, int type, GpuMat& m);
|
||||
|
||||
//! Ensures that size of the given matrix is not less than (rows, cols) size
|
||||
//! and matrix type is match specified one too
|
||||
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m);
|
||||
|
||||
//////////////////////////////// CudaMem ////////////////////////////////
|
||||
// CudaMem is limited cv::Mat with page locked memory allocation.
|
||||
// Page locked memory is only needed for async and faster coping to GPU.
|
||||
|
@ -364,6 +364,10 @@ inline GpuMat createContinuous(Size size, int type)
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void ensureSizeIsEnough(Size size, int type, GpuMat& m)
|
||||
{
|
||||
ensureSizeIsEnough(size.height, size.width, type, m);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
@ -401,6 +405,7 @@ inline CudaMem::CudaMem(const Mat& m, int _alloc_type) : flags(0), rows(0), cols
|
||||
inline CudaMem::~CudaMem()
|
||||
{
|
||||
release();
|
||||
|
||||
}
|
||||
|
||||
inline CudaMem& CudaMem::operator = (const CudaMem& m)
|
||||
|
@ -551,6 +551,13 @@ void cv::gpu::createContinuous(int rows, int cols, int type, GpuMat& m)
|
||||
m = m.reshape(0, rows);
|
||||
}
|
||||
|
||||
void cv::gpu::ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m)
|
||||
{
|
||||
if (m.type() == type && m.rows >= rows && m.cols >= cols)
|
||||
return;
|
||||
m.create(rows, cols, type);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////// CudaMem //////////////////////////////
|
||||
|
@ -159,7 +159,7 @@ Scalar cv::gpu::sum(const GpuMat& src, GpuMat& buf)
|
||||
|
||||
Size bufSize;
|
||||
sum::get_buf_size_required(src.cols, src.rows, src.channels(), bufSize.width, bufSize.height);
|
||||
buf.create(bufSize, CV_8U);
|
||||
ensureSizeIsEnough(bufSize, CV_8U, buf);
|
||||
|
||||
Caller caller = callers[hasAtomicsSupport(getDevice())][src.depth()];
|
||||
if (!caller) CV_Error(CV_StsBadArg, "sum: unsupported type");
|
||||
@ -192,7 +192,7 @@ Scalar cv::gpu::sqrSum(const GpuMat& src, GpuMat& buf)
|
||||
|
||||
Size bufSize;
|
||||
sum::get_buf_size_required(src.cols, src.rows, src.channels(), bufSize.width, bufSize.height);
|
||||
buf.create(bufSize, CV_8U);
|
||||
ensureSizeIsEnough(bufSize, CV_8U, buf);
|
||||
|
||||
Caller caller = callers[hasAtomicsSupport(getDevice())][src.depth()];
|
||||
if (!caller) CV_Error(CV_StsBadArg, "sqrSum: unsupported type");
|
||||
@ -265,7 +265,7 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp
|
||||
|
||||
Size bufSize;
|
||||
get_buf_size_required(src.cols, src.rows, src.elemSize(), bufSize.width, bufSize.height);
|
||||
buf.create(bufSize, CV_8U);
|
||||
ensureSizeIsEnough(bufSize, CV_8U, buf);
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
@ -292,31 +292,31 @@ namespace cv { namespace gpu { namespace mathfunc { namespace minmaxloc {
|
||||
|
||||
template <typename T>
|
||||
void min_max_loc_caller(const DevMem2D src, double* minval, double* maxval,
|
||||
int minloc[2], int maxloc[2], PtrStep valbuf, PtrStep locbuf);
|
||||
int minloc[2], int maxloc[2], PtrStep valBuf, PtrStep locBuf);
|
||||
|
||||
template <typename T>
|
||||
void min_max_loc_mask_caller(const DevMem2D src, const PtrStep mask, double* minval, double* maxval,
|
||||
int minloc[2], int maxloc[2], PtrStep valbuf, PtrStep locbuf);
|
||||
int minloc[2], int maxloc[2], PtrStep valBuf, PtrStep locBuf);
|
||||
|
||||
template <typename T>
|
||||
void min_max_loc_multipass_caller(const DevMem2D src, double* minval, double* maxval,
|
||||
int minloc[2], int maxloc[2], PtrStep valbuf, PtrStep locbuf);
|
||||
int minloc[2], int maxloc[2], PtrStep valBuf, PtrStep locBuf);
|
||||
|
||||
template <typename T>
|
||||
void min_max_loc_mask_multipass_caller(const DevMem2D src, const PtrStep mask, double* minval, double* maxval,
|
||||
int minloc[2], int maxloc[2], PtrStep valbuf, PtrStep locbuf);
|
||||
int minloc[2], int maxloc[2], PtrStep valBuf, PtrStep locBuf);
|
||||
}}}}
|
||||
|
||||
|
||||
void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, const GpuMat& mask)
|
||||
{
|
||||
GpuMat valbuf, locbuf;
|
||||
minMaxLoc(src, minVal, maxVal, minLoc, maxLoc, mask, valbuf, locbuf);
|
||||
GpuMat valBuf, locBuf;
|
||||
minMaxLoc(src, minVal, maxVal, minLoc, maxLoc, mask, valBuf, locBuf);
|
||||
}
|
||||
|
||||
|
||||
void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
|
||||
const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf)
|
||||
const GpuMat& mask, GpuMat& valBuf, GpuMat& locBuf)
|
||||
{
|
||||
using namespace mathfunc::minmaxloc;
|
||||
|
||||
@ -348,23 +348,23 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point
|
||||
int minLoc_[2];
|
||||
int maxLoc_[2];
|
||||
|
||||
Size valbuf_size, locbuf_size;
|
||||
get_buf_size_required(src.cols, src.rows, src.elemSize(), valbuf_size.width,
|
||||
valbuf_size.height, locbuf_size.width, locbuf_size.height);
|
||||
valbuf.create(valbuf_size, CV_8U);
|
||||
locbuf.create(locbuf_size, CV_8U);
|
||||
Size valBufSize, locBufSize;
|
||||
get_buf_size_required(src.cols, src.rows, src.elemSize(), valBufSize.width,
|
||||
valBufSize.height, locBufSize.width, locBufSize.height);
|
||||
ensureSizeIsEnough(valBufSize, CV_8U, valBuf);
|
||||
ensureSizeIsEnough(locBufSize, CV_8U, locBuf);
|
||||
|
||||
if (mask.empty())
|
||||
{
|
||||
Caller caller = callers[hasAtomicsSupport(getDevice())][src.type()];
|
||||
if (!caller) CV_Error(CV_StsBadArg, "minMaxLoc: unsupported type");
|
||||
caller(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf);
|
||||
caller(src, minVal, maxVal, minLoc_, maxLoc_, valBuf, locBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
MaskedCaller caller = masked_callers[hasAtomicsSupport(getDevice())][src.type()];
|
||||
if (!caller) CV_Error(CV_StsBadArg, "minMaxLoc: unsupported type");
|
||||
caller(src, mask, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf);
|
||||
caller(src, mask, minVal, maxVal, minLoc_, maxLoc_, valBuf, locBuf);
|
||||
}
|
||||
|
||||
if (minLoc) { minLoc->x = minLoc_[0]; minLoc->y = minLoc_[1]; }
|
||||
@ -411,9 +411,9 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf)
|
||||
CV_Assert(src.channels() == 1);
|
||||
CV_Assert(src.type() != CV_64F || hasNativeDoubleSupport(getDevice()));
|
||||
|
||||
Size buf_size;
|
||||
get_buf_size_required(src.cols, src.rows, buf_size.width, buf_size.height);
|
||||
buf.create(buf_size, CV_8U);
|
||||
Size bufSize;
|
||||
get_buf_size_required(src.cols, src.rows, bufSize.width, bufSize.height);
|
||||
ensureSizeIsEnough(bufSize, CV_8U, buf);
|
||||
|
||||
Caller caller = callers[hasAtomicsSupport(getDevice())][src.type()];
|
||||
if (!caller) CV_Error(CV_StsBadArg, "countNonZero: unsupported type");
|
||||
|
@ -1,94 +1,94 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GPU_TEST_H_
|
||||
#define _GPU_TEST_H_
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _GPU_TEST_H_
|
||||
#define _GPU_TEST_H_
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <windows.h>
|
||||
#undef min
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include "cxts.h"
|
||||
|
||||
/****************************************************************************************/
|
||||
/* Warnings Disabling */
|
||||
/****************************************************************************************/
|
||||
#if _MSC_VER > 1000
|
||||
#pragma warning(disable : 4514) /* unreferenced inline function has been */
|
||||
/* removed */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant */
|
||||
/* for no warnings in _ASSERT */
|
||||
#pragma warning(disable : 4996) /* deprecated function */
|
||||
#endif
|
||||
|
||||
|
||||
static inline bool check_and_treat_gpu_exception(const cv::Exception& e, CvTS* ts)
|
||||
{
|
||||
switch (e.code)
|
||||
{
|
||||
case CV_GpuNotSupported:
|
||||
ts->printf(CvTS::LOG, "\nGpu not supported by the library");
|
||||
break;
|
||||
|
||||
case CV_GpuApiCallError:
|
||||
ts->printf(CvTS::LOG, "\nGPU Error: %s", e.what());
|
||||
break;
|
||||
|
||||
case CV_GpuNppCallError:
|
||||
ts->printf(CvTS::LOG, "\nNPP Error: %s", e.what());
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
#include "cxts.h"
|
||||
|
||||
/****************************************************************************************/
|
||||
/* Warnings Disabling */
|
||||
/****************************************************************************************/
|
||||
#if _MSC_VER > 1000
|
||||
#pragma warning(disable : 4514) /* unreferenced inline function has been */
|
||||
/* removed */
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant */
|
||||
/* for no warnings in _ASSERT */
|
||||
#pragma warning(disable : 4996) /* deprecated function */
|
||||
#endif
|
||||
|
||||
|
||||
static inline bool check_and_treat_gpu_exception(const cv::Exception& e, CvTS* ts)
|
||||
{
|
||||
switch (e.code)
|
||||
{
|
||||
case CV_GpuNotSupported:
|
||||
ts->printf(CvTS::LOG, "\nGpu not supported by the library");
|
||||
break;
|
||||
|
||||
case CV_GpuApiCallError:
|
||||
ts->printf(CvTS::LOG, "\nGPU Error: %s", e.what());
|
||||
break;
|
||||
|
||||
case CV_GpuNppCallError:
|
||||
ts->printf(CvTS::LOG, "\nNPP Error: %s", e.what());
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
ts->set_failed_test_info(CvTS::FAIL_GENERIC);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user