a big patch; use special proxy types (Input/OutputArray, Input/OutputArrayOfArrays) for passing in vectors, matrices etc.

This commit is contained in:
Vadim Pisarevsky
2011-04-17 13:14:45 +00:00
parent 335370a7c0
commit abeeb40d46
94 changed files with 10831 additions and 9631 deletions

View File

@@ -43,6 +43,10 @@
namespace cv
{
template<> void Ptr<CvHistogram>::delete_obj()
{ cvReleaseHist(&obj); }
////////////////// Helper functions //////////////////////
static const size_t OUT_OF_RANGE = (size_t)1 << (sizeof(size_t)*8 - 2);
@@ -586,18 +590,22 @@ calcHist_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
}
}
}
void calcHist( const Mat* images, int nimages, const int* channels,
const Mat& mask, Mat& hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
void cv::calcHist( const Mat* images, int nimages, const int* channels,
const InputArray& _mask, OutputArray _hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
{
Mat mask = _mask.getMat();
CV_Assert(dims > 0 && histSize);
hist.create(dims, histSize, CV_32F);
Mat ihist = hist;
uchar* histdata = _hist.getMat().data;
_hist.create(dims, histSize, CV_32F);
Mat hist = _hist.getMat(), ihist = hist;
ihist.flags = (ihist.flags & ~CV_MAT_TYPE_MASK)|CV_32S;
if( !accumulate )
if( !accumulate || histdata != hist.data )
hist = Scalar(0.);
else
hist.convertTo(ihist, CV_32S);
@@ -626,7 +634,9 @@ void calcHist( const Mat* images, int nimages, const int* channels,
ihist.convertTo(hist, CV_32F);
}
namespace cv
{
template<typename T> static void
calcSparseHist_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
Size imsize, SparseMat& hist, int dims, const float** _ranges,
@@ -803,11 +813,13 @@ static void calcHist( const Mat* images, int nimages, const int* channels,
}
}
}
void calcHist( const Mat* images, int nimages, const int* channels,
const Mat& mask, SparseMat& hist, int dims, const int* histSize,
void cv::calcHist( const Mat* images, int nimages, const int* channels,
const InputArray& _mask, SparseMat& hist, int dims, const int* histSize,
const float** ranges, bool uniform, bool accumulate )
{
Mat mask = _mask.getMat();
calcHist( images, nimages, channels, mask, hist, dims, histSize,
ranges, uniform, accumulate, false );
}
@@ -815,6 +827,8 @@ void calcHist( const Mat* images, int nimages, const int* channels,
/////////////////////////////////////// B A C K P R O J E C T ////////////////////////////////////
namespace cv
{
template<typename T, typename BT> static void
calcBackProj_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
@@ -1102,12 +1116,14 @@ calcBackProj_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
}
}
}
}
void calcBackProject( const Mat* images, int nimages, const int* channels,
const Mat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
void cv::calcBackProject( const Mat* images, int nimages, const int* channels,
const InputArray& _hist, OutputArray _backProject,
const float** ranges, double scale, bool uniform )
{
Mat hist = _hist.getMat();
vector<uchar*> ptrs;
vector<int> deltas;
vector<double> uniranges;
@@ -1115,7 +1131,8 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
int dims = hist.dims == 2 && hist.size[1] == 1 ? 1 : hist.dims;
CV_Assert( dims > 0 && hist.data );
backProject.create( images[0].size(), images[0].depth() );
_backProject.create( images[0].size(), images[0].depth() );
Mat backProject = _backProject.getMat();
histPrepareImages( images, nimages, channels, backProject, dims, hist.size, ranges,
uniform, ptrs, deltas, imsize, uniranges );
const double* _uniranges = uniform ? &uniranges[0] : 0;
@@ -1131,7 +1148,10 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
CV_Error(CV_StsUnsupportedFormat, "");
}
namespace cv
{
template<typename T, typename BT> static void
calcSparseBackProj_( vector<uchar*>& _ptrs, const vector<int>& _deltas,
Size imsize, const SparseMat& hist, int dims, const float** _ranges,
@@ -1259,11 +1279,12 @@ calcSparseBackProj_8u( vector<uchar*>& _ptrs, const vector<int>& _deltas,
ptrs[i] += deltas[i*2 + 1];
}
}
void calcBackProject( const Mat* images, int nimages, const int* channels,
const SparseMat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
}
void cv::calcBackProject( const Mat* images, int nimages, const int* channels,
const SparseMat& hist, Mat& backProject,
const float** ranges, double scale, bool uniform )
{
vector<uchar*> ptrs;
vector<int> deltas;
@@ -1295,13 +1316,14 @@ void calcBackProject( const Mat* images, int nimages, const int* channels,
////////////////// C O M P A R E H I S T O G R A M S ////////////////////////
double compareHist( const Mat& H1, const Mat& H2, int method )
double cv::compareHist( const InputArray& _H1, const InputArray& _H2, int method )
{
Mat H1 = _H1.getMat(), H2 = _H2.getMat();
const Mat* arrays[] = {&H1, &H2, 0};
Mat planes[2];
NAryMatIterator it(arrays, planes);
double result = 0;
int i, len;
int j, len = (int)it.size;
CV_Assert( H1.type() == H2.type() && H1.type() == CV_32F );
@@ -1309,7 +1331,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
CV_Assert( it.planes[0].isContinuous() && it.planes[1].isContinuous() );
for( i = 0; i < it.nplanes; i++, ++it )
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
const float* h1 = (const float*)it.planes[0].data;
const float* h2 = (const float*)it.planes[1].data;
@@ -1317,20 +1339,20 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
if( method == CV_COMP_CHISQR )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i] - h2[i];
double b = h1[i] + h2[i];
double a = h1[j] - h2[j];
double b = h1[j] + h2[j];
if( fabs(b) > FLT_EPSILON )
result += a*a/b;
}
}
else if( method == CV_COMP_CORREL )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i];
double b = h2[i];
double a = h1[j];
double b = h2[j];
s12 += a*b;
s1 += a;
@@ -1341,15 +1363,15 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
}
else if( method == CV_COMP_INTERSECT )
{
for( i = 0; i < len; i++ )
result += std::min(h1[i], h2[i]);
for( j = 0; j < len; j++ )
result += std::min(h1[j], h2[j]);
}
else if( method == CV_COMP_BHATTACHARYYA )
{
for( i = 0; i < len; i++ )
for( j = 0; j < len; j++ )
{
double a = h1[i];
double b = h2[i];
double a = h1[j];
double b = h2[j];
result += std::sqrt(a*b);
s1 += a;
s2 += b;
@@ -1361,9 +1383,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
if( method == CV_COMP_CORREL )
{
size_t total = 1;
for( i = 0; i < H1.dims; i++ )
total *= H1.size[i];
size_t total = H1.total();
double scale = 1./total;
double num = s12 - s1*s2*scale;
double denom2 = (s11 - s1*s1*scale)*(s22 - s2*s2*scale);
@@ -1380,7 +1400,7 @@ double compareHist( const Mat& H1, const Mat& H2, int method )
}
double compareHist( const SparseMat& H1, const SparseMat& H2, int method )
double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
{
double result = 0;
int i, dims = H1.dims();
@@ -1491,12 +1511,6 @@ double compareHist( const SparseMat& H1, const SparseMat& H2, int method )
}
template<> void Ptr<CvHistogram>::delete_obj()
{ cvReleaseHist(&obj); }
}
const int CV_HIST_DEFAULT_TYPE = CV_32F;
/* Creates new histogram */
@@ -2395,11 +2409,13 @@ CV_IMPL void cvEqualizeHist( const CvArr* srcarr, CvArr* dstarr )
}
void cv::equalizeHist( const Mat& src, Mat& dst )
void cv::equalizeHist( const InputArray& _src, OutputArray _dst )
{
dst.create( src.size(), src.type() );
CvMat _src = src, _dst = dst;
cvEqualizeHist( &_src, &_dst );
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
CvMat _csrc = src, _cdst = dst;
cvEqualizeHist( &_csrc, &_cdst );
}
/* Implementation of RTTI and Generic Functions for CvHistogram */