Commit d8c8339b authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

the first draft of transparent API and new UMat class. more files

parent 278fb617
......@@ -158,6 +158,9 @@ enum { REDUCE_SUM = 0,
//! swaps two matrices
CV_EXPORTS void swap(Mat& a, Mat& b);
//! swaps two umatrices
CV_EXPORTS void swap( UMat& a, UMat& b );
//! 1D interpolation function: returns coordinate of the "donor" pixel for the specified location p.
CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType);
......@@ -439,7 +442,7 @@ CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, M
//! computes covariation matrix of a set of samples
CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar,
OutputArray mean, int flags, int ctype = CV_64F);
InputOutputArray mean, int flags, int ctype = CV_64F);
CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean,
OutputArray eigenvectors, int maxComponents = 0);
......
......@@ -472,6 +472,9 @@ class CV_EXPORTS RNG;
class CV_EXPORTS Mat;
class CV_EXPORTS MatExpr;
class CV_EXPORTS UMat;
class CV_EXPORTS UMatExpr;
class CV_EXPORTS SparseMat;
typedef Mat MatND;
......
This diff is collapsed.
......@@ -271,7 +271,7 @@ void cv::split(InputArray _m, OutputArrayOfArrays _mv)
_mv.release();
return;
}
CV_Assert( !_mv.fixedType() || CV_MAT_TYPE(_mv.flags) == m.depth() );
CV_Assert( !_mv.fixedType() || _mv.type() == m.depth() );
_mv.create(m.channels(), 1, m.depth());
Mat* dst = &_mv.getMatRef(0);
split(m, dst);
......
......@@ -1610,7 +1610,7 @@ MatExpr Mat::mul(InputArray m, double scale) const
MatExpr e;
if(m.kind() == _InputArray::EXPR)
{
const MatExpr& me = *(const MatExpr*)m.obj;
const MatExpr& me = *(const MatExpr*)m.getObj();
me.op->multiply(MatExpr(*this), me, e, scale);
}
else
......
This diff is collapsed.
......@@ -50,6 +50,7 @@
#include "opencv2/core/private.hpp"
#include "opencv2/core/private.cuda.hpp"
#include "opencv2/core/ocl.hpp"
#include <assert.h>
#include <ctype.h>
......@@ -215,6 +216,19 @@ inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
struct TLSData
{
TLSData();
RNG rng;
int device;
ocl::Queue oclQueue;
int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized
static TLSData* get();
};
namespace ocl { MatAllocator* getOpenCLAllocator(); }
}
#endif /*_CXCORE_INTERNAL_H_*/
......@@ -727,85 +727,11 @@ void RNG::fill( InputOutputArray _mat, int disttype,
}
}
#ifdef WIN32
#ifdef HAVE_WINRT
// using C++11 thread attribute for local thread data
__declspec( thread ) RNG* rng = NULL;
void deleteThreadRNGData()
{
if (rng)
delete rng;
}
RNG& theRNG()
cv::RNG& cv::theRNG()
{
if (!rng)
{
rng = new RNG;
}
return *rng;
}
#else
#ifdef WINCE
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif
static DWORD tlsRNGKey = TLS_OUT_OF_INDEXES;
void deleteThreadRNGData()
{
if( tlsRNGKey != TLS_OUT_OF_INDEXES )
delete (RNG*)TlsGetValue( tlsRNGKey );
}
RNG& theRNG()
{
if( tlsRNGKey == TLS_OUT_OF_INDEXES )
{
tlsRNGKey = TlsAlloc();
CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
}
RNG* rng = (RNG*)TlsGetValue( tlsRNGKey );
if( !rng )
{
rng = new RNG;
TlsSetValue( tlsRNGKey, rng );
}
return *rng;
}
#endif //HAVE_WINRT
#else
static pthread_key_t tlsRNGKey = 0;
static pthread_once_t tlsRNGKeyOnce = PTHREAD_ONCE_INIT;
static void deleteRNG(void* data)
{
delete (RNG*)data;
}
static void makeRNGKey()
{
int errcode = pthread_key_create(&tlsRNGKey, deleteRNG);
CV_Assert(errcode == 0);
}
RNG& theRNG()
{
pthread_once(&tlsRNGKeyOnce, makeRNGKey);
RNG* rng = (RNG*)pthread_getspecific(tlsRNGKey);
if( !rng )
{
rng = new RNG;
pthread_setspecific(tlsRNGKey, rng);
}
return *rng;
}
#endif
return TLSData::get()->rng;
}
void cv::randu(InputOutputArray dst, InputArray low, InputArray high)
......
......@@ -830,4 +830,92 @@ bool Mutex::trylock() { return impl->trylock(); }
}
//////////////////////////////// thread-local storage ////////////////////////////////
namespace cv
{
TLSData::TLSData()
{
device = 0;
useOpenCL = -1;
}
#ifdef WIN32
#ifdef HAVE_WINRT
// using C++11 thread attribute for local thread data
static __declspec( thread ) TLSData* g_tlsdata = NULL;
static void deleteThreadRNGData()
{
if (g_tlsdata)
delete g_tlsdata;
}
TLSData* TLSData::get()
{
if (!g_tlsdata)
{
g_tlsdata = new TLSData;
}
return g_tlsdata;
}
#else
#ifdef WINCE
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
#endif
static DWORD tlsKey = TLS_OUT_OF_INDEXES;
void deleteThreadData()
{
if( tlsKey != TLS_OUT_OF_INDEXES )
delete (TLSData*)TlsGetValue( tlsKey );
}
TLSData* TLSData::get()
{
if( tlsKey == TLS_OUT_OF_INDEXES )
{
tlsRNGKey = TlsAlloc();
CV_Assert(tlsRNGKey != TLS_OUT_OF_INDEXES);
}
TLSData* d = (TLSData*)TlsGetValue( tlsKey );
if( !d )
{
d = new TLSData;
TlsSetValue( tlsRNGKey, d );
}
return d;
}
#endif //HAVE_WINRT
#else
static pthread_key_t tlsKey = 0;
static pthread_once_t tlsKeyOnce = PTHREAD_ONCE_INIT;
static void deleteTLSData(void* data)
{
delete (TLSData*)data;
}
static void makeKey()
{
int errcode = pthread_key_create(&tlsKey, deleteTLSData);
CV_Assert(errcode == 0);
}
TLSData* TLSData::get()
{
pthread_once(&tlsKeyOnce, makeKey);
TLSData* d = (TLSData*)pthread_getspecific(tlsKey);
if( !d )
{
d = new TLSData;
pthread_setspecific(tlsKey, d);
}
return d;
}
#endif
}
/* End of file. */
......@@ -9,7 +9,7 @@ using std::tr1::get;
typedef tr1::tuple<Size, MatType> Size_Source_t;
typedef TestBaseWithParam<Size_Source_t> Size_Source;
typedef TestBaseWithParam<Size> MatSize;
typedef TestBaseWithParam<Size> TestMatSize;
static const float rangeHight = 256.0f;
static const float rangeLow = 0.0f;
......@@ -99,7 +99,7 @@ PERF_TEST_P(Size_Source, calcHist3d,
SANITY_CHECK(hist);
}
PERF_TEST_P(MatSize, equalizeHist,
PERF_TEST_P(TestMatSize, equalizeHist,
testing::Values(TYPICAL_MAT_SIZES)
)
{
......
......@@ -102,7 +102,8 @@ float
CvEM::predict( const CvMat* _sample, CvMat* _probs ) const
{
Mat prbs0 = cvarrToMat(_probs), prbs = prbs0, sample = cvarrToMat(_sample);
int cls = static_cast<int>(emObj.predict(sample, _probs ? _OutputArray(prbs) : cv::noArray())[1]);
int cls = static_cast<int>(emObj.predict(sample, _probs ? _OutputArray(prbs) :
(OutputArray)cv::noArray())[1]);
if(_probs)
{
if( prbs.data != prbs0.data )
......@@ -208,13 +209,16 @@ bool CvEM::train( const Mat& _samples, const Mat& _sample_idx,
bool isOk = false;
if( _params.start_step == EM::START_AUTO_STEP )
isOk = emObj.train(_samples,
logLikelihoods, _labels ? _OutputArray(*_labels) : cv::noArray(), probs);
logLikelihoods, _labels ? _OutputArray(*_labels) :
(OutputArray)cv::noArray(), probs);
else if( _params.start_step == EM::START_E_STEP )
isOk = emObj.trainE(_samples, means, covshdrs, weights,
logLikelihoods, _labels ? _OutputArray(*_labels) : cv::noArray(), probs);
logLikelihoods, _labels ? _OutputArray(*_labels) :
(OutputArray)cv::noArray(), probs);
else if( _params.start_step == EM::START_M_STEP )
isOk = emObj.trainM(_samples, prbs,
logLikelihoods, _labels ? _OutputArray(*_labels) : cv::noArray(), probs);
logLikelihoods, _labels ? _OutputArray(*_labels) :
(OutputArray)cv::noArray(), probs);
else
CV_Error(CV_StsBadArg, "Bad start type of EM algorithm");
......@@ -230,7 +234,9 @@ bool CvEM::train( const Mat& _samples, const Mat& _sample_idx,
float
CvEM::predict( const Mat& _sample, Mat* _probs ) const
{
return static_cast<float>(emObj.predict(_sample, _probs ? _OutputArray(*_probs) : cv::noArray())[1]);
return static_cast<float>(emObj.predict(_sample, _probs ?
_OutputArray(*_probs) :
(OutputArray)cv::noArray())[1]);
}
int CvEM::getNClusters() const
......
......@@ -82,7 +82,7 @@ cvExtractSURF( const CvArr* _img, const CvArr* _mask,
surf->set("upright", params.upright != 0);
surf->set("extended", params.extended != 0);
surf->operator()(img, mask, kpt, _descriptors ? _OutputArray(descr) : noArray(),
surf->operator()(img, mask, kpt, _descriptors ? _OutputArray(descr) : (OutputArray)noArray(),
useProvidedKeyPts != 0);
if( _keypoints )
......
......@@ -154,30 +154,24 @@ void cv::ocl::oclMat::upload(const Mat &m)
cv::ocl::oclMat::operator cv::_InputArray()
{
_InputArray newInputArray;
newInputArray.flags = cv::_InputArray::OCL_MAT;
newInputArray.obj = reinterpret_cast<void *>(this);
return newInputArray;
return _InputArray(cv::_InputArray::OCL_MAT, this);
}
cv::ocl::oclMat::operator cv::_OutputArray()
{
_OutputArray newOutputArray;
newOutputArray.flags = cv::_InputArray::OCL_MAT;
newOutputArray.obj = reinterpret_cast<void *>(this);
return newOutputArray;
return _OutputArray(cv::_InputArray::OCL_MAT, this);
}
cv::ocl::oclMat& cv::ocl::getOclMatRef(InputArray src)
{
CV_Assert(src.flags & cv::_InputArray::OCL_MAT);
return *reinterpret_cast<oclMat*>(src.obj);
CV_Assert(src.kind() == cv::_InputArray::OCL_MAT);
return *(oclMat*)src.getObj();
}
cv::ocl::oclMat& cv::ocl::getOclMatRef(OutputArray src)
{
CV_Assert(src.flags & cv::_InputArray::OCL_MAT);
return *reinterpret_cast<oclMat*>(src.obj);
CV_Assert(src.kind() == cv::_InputArray::OCL_MAT);
return *(oclMat*)src.getObj();
}
void cv::ocl::oclMat::download(cv::Mat &m) const
......
......@@ -163,7 +163,9 @@ namespace
void Farneback::impl(const Mat& input0, const Mat& input1, OutputArray dst)
{
calcOpticalFlowFarneback(input0, input1, dst, pyrScale_, numLevels_, winSize_, numIters_, polyN_, polySigma_, flags_);
calcOpticalFlowFarneback(input0, input1, (InputOutputArray)dst, pyrScale_,
numLevels_, winSize_, numIters_,
polyN_, polySigma_, flags_);
}
}
......@@ -325,7 +327,7 @@ namespace
alg_->set("iterations", iterations_);
alg_->set("useInitialFlow", useInitialFlow_);
alg_->calc(input0, input1, dst);
alg_->calc(input0, input1, (InputOutputArray)dst);
}
void DualTVL1::collectGarbage()
......
......@@ -352,7 +352,7 @@ cvCalcOpticalFlowPyrLK( const void* arrA, const void* arrB,
if( error )
err = cv::Mat(count, 1, CV_32F, (void*)error);
cv::calcOpticalFlowPyrLK( A, B, ptA, ptB, st,
error ? cv::_OutputArray(err) : cv::noArray(),
error ? cv::_OutputArray(err) : (cv::_OutputArray)cv::noArray(),
winSize, level, criteria, flags);
}
......
......@@ -564,7 +564,7 @@ FarnebackUpdateFlow_GaussianBlur( const Mat& _R0, const Mat& _R1,
}
void cv::calcOpticalFlowFarneback( InputArray _prev0, InputArray _next0,
OutputArray _flow0, double pyr_scale, int levels, int winsize,
InputOutputArray _flow0, double pyr_scale, int levels, int winsize,
int iterations, int poly_n, double poly_sigma, int flags )
{
Mat prev0 = _prev0.getMat(), next0 = _next0.getMat();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment