fixed warnings in gbt; added insertChannel() and extractChannel(); made the code "rand{u|n}(arr, <number>, <number>)" work properly.

This commit is contained in:
Vadim Pisarevsky 2011-06-18 10:56:49 +00:00
parent c37e063914
commit 0e14fef96e
4 changed files with 58 additions and 15 deletions

View File

@ -1961,7 +1961,7 @@ CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1); CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage //! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage
CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1); CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1);
//! adds one matrix to another (dst = src1 + src2) //! adds one matrix to another (dst = src1 + src2)
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst,
InputArray mask=noArray(), int dtype=-1); InputArray mask=noArray(), int dtype=-1);
@ -2039,6 +2039,12 @@ CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts
CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst, CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
const int* fromTo, size_t npairs); const int* fromTo, size_t npairs);
//! extracts a single channel from src (coi is 0-based index)
CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
//! inserts a single channel to dst (coi is 0-based index)
CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi);
//! reverses the order of the rows, columns or both in a matrix //! reverses the order of the rows, columns or both in a matrix
CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode); CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode);

View File

@ -501,7 +501,26 @@ void cv::mixChannels(const vector<Mat>& src, vector<Mat>& dst,
{ {
mixChannels(!src.empty() ? &src[0] : 0, src.size(), mixChannels(!src.empty() ? &src[0] : 0, src.size(),
!dst.empty() ? &dst[0] : 0, dst.size(), fromTo, npairs); !dst.empty() ? &dst[0] : 0, dst.size(), fromTo, npairs);
} }
void cv::extractChannel(InputArray _src, OutputArray _dst, int coi)
{
Mat src = _src.getMat();
CV_Assert( 0 <= coi && coi < src.channels() );
_dst.create(src.dims, &src.size[0], src.depth());
Mat dst = _dst.getMat();
int ch[] = { coi, 0 };
mixChannels(&src, 1, &dst, 1, ch, 1);
}
void cv::insertChannel(InputArray _src, InputOutputArray _dst, int coi)
{
Mat src = _src.getMat(), dst = _dst.getMat();
CV_Assert( src.size == dst.size && src.depth() == dst.depth() );
CV_Assert( 0 <= coi && coi < dst.channels() && src.channels() == 1 );
int ch[] = { 0, coi };
mixChannels(&src, 1, &dst, 1, ch, 1);
}
/****************************************************************************************\ /****************************************************************************************\
* convertScale[Abs] * * convertScale[Abs] *

View File

@ -453,11 +453,11 @@ void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, Inpu
RandnScaleFunc scaleFunc = 0; RandnScaleFunc scaleFunc = 0;
CV_Assert(_param1.channels() == 1 && (_param1.rows == 1 || _param1.cols == 1) && CV_Assert(_param1.channels() == 1 && (_param1.rows == 1 || _param1.cols == 1) &&
(_param1.rows + _param1.cols - 1 == cn || (_param1.rows + _param1.cols - 1 == cn || _param1.rows + _param1.cols - 1 == 1 ||
(_param1.size() == Size(1, 4) && _param1.type() == CV_64F && cn <= 4))); (_param1.size() == Size(1, 4) && _param1.type() == CV_64F && cn <= 4)));
CV_Assert( _param2.channels() == 1 && CV_Assert( _param2.channels() == 1 &&
(((_param2.rows == 1 || _param2.cols == 1) && (((_param2.rows == 1 || _param2.cols == 1) &&
(_param2.rows + _param2.cols - 1 == cn || (_param2.rows + _param2.cols - 1 == cn || _param2.rows + _param2.cols - 1 == 1 ||
(_param1.size() == Size(1, 4) && _param1.type() == CV_64F && cn <= 4))) || (_param1.size() == Size(1, 4) && _param1.type() == CV_64F && cn <= 4))) ||
(_param2.rows == cn && _param2.cols == cn && disttype == NORMAL))); (_param2.rows == cn && _param2.cols == cn && disttype == NORMAL)));
@ -468,26 +468,34 @@ void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, Inpu
uchar* mean = 0; uchar* mean = 0;
uchar* stddev = 0; uchar* stddev = 0;
bool stdmtx = false; bool stdmtx = false;
int n1 = (int)_param1.total();
int n2 = (int)_param2.total();
if( disttype == UNIFORM ) if( disttype == UNIFORM )
{ {
_parambuf.allocate(cn*8); _parambuf.allocate(cn*8 + n1 + n2);
double* parambuf = _parambuf; double* parambuf = _parambuf;
const double* p1 = (const double*)_param1.data; double* p1 = (double*)_param1.data;
const double* p2 = (const double*)_param2.data; double* p2 = (double*)_param2.data;
if( !_param1.isContinuous() || _param1.type() != CV_64F ) if( !_param1.isContinuous() || _param1.type() != CV_64F || n1 != cn )
{ {
Mat tmp(_param1.size(), CV_64F, parambuf); Mat tmp(_param1.size(), CV_64F, parambuf);
_param1.convertTo(tmp, CV_64F); _param1.convertTo(tmp, CV_64F);
p1 = parambuf; p1 = parambuf;
if( n1 < cn )
for( j = n1; j < cn; j++ )
p1[j] = p1[j-n1];
} }
if( !_param2.isContinuous() || _param2.type() != CV_64F ) if( !_param2.isContinuous() || _param2.type() != CV_64F || n2 != cn )
{ {
Mat tmp(_param2.size(), CV_64F, parambuf + cn); Mat tmp(_param2.size(), CV_64F, parambuf + cn);
_param2.convertTo(tmp, CV_64F); _param2.convertTo(tmp, CV_64F);
p2 = parambuf + cn; p2 = parambuf + cn;
if( n2 < cn )
for( j = n2; j < cn; j++ )
p2[j] = p2[j-n2];
} }
if( depth <= CV_32S ) if( depth <= CV_32S )
@ -559,10 +567,12 @@ void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, Inpu
} }
else if( disttype == CV_RAND_NORMAL ) else if( disttype == CV_RAND_NORMAL )
{ {
_parambuf.allocate(_param1.total() + _param2.total()); _parambuf.allocate(MAX(n1, cn) + MAX(n2, cn));
double* parambuf = _parambuf; double* parambuf = _parambuf;
int ptype = depth == CV_64F ? CV_64F : CV_32F; int ptype = depth == CV_64F ? CV_64F : CV_32F;
int esz = (int)CV_ELEM_SIZE(ptype);
if( _param1.isContinuous() && _param1.type() == ptype ) if( _param1.isContinuous() && _param1.type() == ptype )
mean = _param1.data; mean = _param1.data;
else else
@ -572,6 +582,10 @@ void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, Inpu
mean = (uchar*)parambuf; mean = (uchar*)parambuf;
} }
if( n1 < cn )
for( j = n1*esz; j < cn*esz; j++ )
mean[j] = mean[j - n1*esz];
if( _param2.isContinuous() && _param2.type() == ptype ) if( _param2.isContinuous() && _param2.type() == ptype )
stddev = _param2.data; stddev = _param2.data;
else else
@ -581,6 +595,10 @@ void RNG::fill( InputOutputArray _mat, int disttype, InputArray _param1arg, Inpu
stddev = (uchar*)(parambuf + cn); stddev = (uchar*)(parambuf + cn);
} }
if( n1 < cn )
for( j = n1*esz; j < cn*esz; j++ )
stddev[j] = stddev[j - n1*esz];
stdmtx = _param2.rows == cn && _param2.cols == cn; stdmtx = _param2.rows == cn && _param2.cols == cn;
scaleFunc = randnScaleTab[depth]; scaleFunc = randnScaleTab[depth];
CV_Assert( scaleFunc != 0 ); CV_Assert( scaleFunc != 0 );

View File

@ -919,17 +919,17 @@ public:
Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {} Tree_predictor() : weak(0), sum(0), k(0), sample(0), missing(0), shrinkage(1.0f) {}
Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage, Tree_predictor(pCvSeq* _weak, const int _k, const float _shrinkage,
const CvMat* _sample, const CvMat* _missing, float* _sum ) : const CvMat* _sample, const CvMat* _missing, float* _sum ) :
weak(_weak), k(_k), sample(_sample), weak(_weak), sum(_sum), k(_k), sample(_sample),
missing(_missing), sum(_sum), shrinkage(_shrinkage) missing(_missing), shrinkage(_shrinkage)
{} {}
Tree_predictor( const Tree_predictor& p, cv::Split ) : Tree_predictor( const Tree_predictor& p, cv::Split ) :
weak(p.weak), k(p.k), sample(p.sample), weak(p.weak), sum(p.sum), k(p.k), sample(p.sample),
missing(p.missing), sum(p.sum), shrinkage(p.shrinkage) missing(p.missing), shrinkage(p.shrinkage)
{} {}
Tree_predictor& operator=( const Tree_predictor& ) Tree_predictor& operator=( const Tree_predictor& )
{} { return *this; }
virtual void operator()(const cv::BlockedRange& range) const virtual void operator()(const cv::BlockedRange& range) const
{ {