本文整理汇总了C++中CV_MAT_TYPE函数的典型用法代码示例。如果您正苦于以下问题:C++ CV_MAT_TYPE函数的具体用法?C++ CV_MAT_TYPE怎么用?C++ CV_MAT_TYPE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CV_MAT_TYPE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cvLSHQuery
void cvLSHQuery(CvLSH* lsh, const CvMat* data, CvMat* indices, CvMat* dist, int k, int emax) {
int dims;
switch (lsh->type) {
case CV_32FC1: dims = lsh->u.lsh_32f->dims(); break;
case CV_64FC1: dims = lsh->u.lsh_64f->dims(); break;
default: assert(0); return;
}
if (k<1)
CV_Error(CV_StsOutOfRange, "k must be positive");
if (CV_MAT_TYPE(data->type) != lsh->type)
CV_Error(CV_StsUnsupportedFormat, "type of data and constructed LSH must agree");
if (dims != data->cols)
CV_Error(CV_StsBadSize, "data must be n x d, where d is what was used to construct LSH");
if (dist->rows != data->rows || dist->cols != k)
CV_Error(CV_StsBadSize, "dist must be n x k for n x d data");
if (dist->rows != indices->rows || dist->cols != indices->cols)
CV_Error(CV_StsBadSize, "dist and indices must be same size");
if (CV_MAT_TYPE(dist->type) != CV_64FC1)
CV_Error(CV_StsUnsupportedFormat, "dist must be CV_64FC1");
if (CV_MAT_TYPE(indices->type) != CV_32SC1)
CV_Error(CV_StsUnsupportedFormat, "indices must be CV_32SC1");
switch (lsh->type) {
case CV_32FC1: lsh->u.lsh_32f->query(data->data.fl, data->rows,
k, emax, dist->data.db, indices->data.i); break;
case CV_64FC1: lsh->u.lsh_64f->query(data->data.db, data->rows,
k, emax, dist->data.db, indices->data.i); break;
default: assert(0); return;
}
}
示例2: CV_MAT_TYPE
int grow_mat::init(int r, int c, int type, int maxrows, int maxcols)
{
int no_max = 0;
if (maxrows==0) {maxrows=r*_expand_factor;no_max=1;}
if (maxcols==0) {maxcols=c*_expand_factor;no_max=1;}
if (type==0) type=CV_64FC1;
if (r<=0 || c<=0 || maxrows<0 || maxcols<0 || r>maxrows || c>maxcols)
return 0;
// 为了和mini_solver的set_solver一致,允许再次初始化!
if (_mat)
{
// 若矩阵_mat存在,且类型相同,表示客户想改变大小。
int mat_type = CV_MAT_TYPE(_mat->type);
if (CV_MAT_TYPE(type)==mat_type)
{
return resize(r,c);
}
}
if(_mat) cvReleaseMat(&_mat);
if (no_max)
_mat = cvCreateMat(r, c, type);
else
_mat = cvCreateMat(maxrows, maxcols, type);
if (_mat==0) return 0;
if (_zero_flag) cvSetZero(_mat);
cvGetSubRect(_mat, this, cvRect(0,0,c,r));
return 1;
}
示例3: cvLSHAdd
void cvLSHAdd(CvLSH* lsh, const CvMat* data, CvMat* indices) {
int dims, n;
int* ret_indices = 0;
switch (lsh->type) {
case CV_32FC1: dims = lsh->u.lsh_32f->dims(); break;
case CV_64FC1: dims = lsh->u.lsh_64f->dims(); break;
default: assert(0); return;
}
n = data->rows;
if (dims != data->cols)
CV_Error(CV_StsBadSize, "data must be n x d, where d is what was used to construct LSH");
if (CV_MAT_TYPE(data->type) != lsh->type)
CV_Error(CV_StsUnsupportedFormat, "type of data and constructed LSH must agree");
if (indices) {
if (CV_MAT_TYPE(indices->type) != CV_32SC1)
CV_Error(CV_StsUnsupportedFormat, "indices must be CV_32SC1");
if (indices->rows * indices->cols != n)
CV_Error(CV_StsBadSize, "indices must be n x 1 or 1 x n for n x d data");
ret_indices = indices->data.i;
}
switch (lsh->type) {
case CV_32FC1: lsh->u.lsh_32f->add(data->data.fl, n, ret_indices); break;
case CV_64FC1: lsh->u.lsh_64f->add(data->data.db, n, ret_indices); break;
default: assert(0); return;
}
}
示例4: cvCalcOpticalFlowLK
/*F///////////////////////////////////////////////////////////////////////////////////////
// Name: cvCalcOpticalFlowLK
// Purpose: Optical flow implementation
// Context:
// Parameters:
// srcA, srcB - source image
// velx, vely - destination image
// Returns:
//
// Notes:
//F*/
CV_IMPL void
cvCalcOpticalFlowLK(const void* srcarrA, const void* srcarrB, CvSize winSize,
void* velarrx, void* velarry) {
CvMat stubA, *srcA = cvGetMat(srcarrA, &stubA);
CvMat stubB, *srcB = cvGetMat(srcarrB, &stubB);
CvMat stubx, *velx = cvGetMat(velarrx, &stubx);
CvMat stuby, *vely = cvGetMat(velarry, &stuby);
if (!CV_ARE_TYPES_EQ(srcA, srcB)) {
CV_Error(CV_StsUnmatchedFormats, "Source images have different formats");
}
if (!CV_ARE_TYPES_EQ(velx, vely)) {
CV_Error(CV_StsUnmatchedFormats, "Destination images have different formats");
}
if (!CV_ARE_SIZES_EQ(srcA, srcB) ||
!CV_ARE_SIZES_EQ(velx, vely) ||
!CV_ARE_SIZES_EQ(srcA, velx)) {
CV_Error(CV_StsUnmatchedSizes, "");
}
if (CV_MAT_TYPE(srcA->type) != CV_8UC1 ||
CV_MAT_TYPE(velx->type) != CV_32FC1)
CV_Error(CV_StsUnsupportedFormat, "Source images must have 8uC1 type and "
"destination images must have 32fC1 type");
if (srcA->step != srcB->step || velx->step != vely->step) {
CV_Error(CV_BadStep, "source and destination images have different step");
}
IPPI_CALL(icvCalcOpticalFlowLK_8u32fR((uchar*)srcA->data.ptr, (uchar*)srcB->data.ptr,
srcA->step, cvGetMatSize(srcA), winSize,
velx->data.fl, vely->data.fl, velx->step));
}
示例5: CVAPI
CVAPI(void) cvShowImageEx(const char * id, const CvArr * arr,
const int cm)
{
CvMat * src, src_stub;
double minval, maxval, maxdiff; CvPoint minloc, maxloc;
int type = cvGetElemType(arr);
CvMat * disp, * src_scaled;
int i, j;
if (!CV_IS_MAT(arr))
src = cvGetMat(arr, &src_stub);
else{
src = (CvMat*)arr;
}
src = cvCloneMat(src);
if ( (src->rows<60) || (src->rows<60) )
{
CvMat * orig = cvCloneMat(src);
int scale=60./MIN(orig->rows, orig->cols);
cvReleaseMat(&src);
src = cvCreateMat(orig->rows*scale, orig->cols*scale,
CV_MAT_TYPE(orig->type));
int m,n;
if (CV_MAT_TYPE(src->type)==CV_64F){
for (m=0;m<orig->rows;m++) {
for (n=0;n<orig->cols;n++) {
for (i=0;i<scale;i++) {
for (j=0;j<scale;j++) {
CV_MAT_ELEM(*src, double, m*scale+i, n*scale+j) = CV_MAT_ELEM(*orig, double, m, n);
}
}
}
}
}else if (CV_MAT_TYPE(src->type)==CV_32F){
示例6: cvCornerMinEigenVal
CV_IMPL void
cvCornerMinEigenVal( const void* srcarr, void* eigenvarr,
int block_size, int aperture_size )
{
CV_FUNCNAME( "cvCornerMinEigenVal" );
__BEGIN__;
CvMat stub, *src = (CvMat*)srcarr;
CvMat eigstub, *eigenv = (CvMat*)eigenvarr;
CV_CALL( src = cvGetMat( srcarr, &stub ));
CV_CALL( eigenv = cvGetMat( eigenv, &eigstub ));
if( CV_MAT_TYPE(src->type) != CV_8UC1 && CV_MAT_TYPE(src->type) != CV_32FC1 ||
CV_MAT_TYPE(eigenv->type) != CV_32FC1 )
CV_ERROR( CV_StsUnsupportedFormat, "Input must be 8uC1 or 32fC1, output must be 32fC1" );
if( !CV_ARE_SIZES_EQ( src, eigenv ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
CV_CALL( icvCornerEigenValsVecs( src, eigenv, block_size, aperture_size, ICV_MINEIGENVAL ));
__END__;
}
示例7: cvCornerHarris
CV_IMPL void
cvCornerHarris( const CvArr* srcarr, CvArr* harris_responce,
int block_size, int aperture_size, double k )
{
CV_FUNCNAME( "cvCornerHarris" );
__BEGIN__;
CvMat stub, *src = (CvMat*)srcarr;
CvMat eigstub, *eigenv = (CvMat*)harris_responce;
CV_CALL( src = cvGetMat( srcarr, &stub ));
CV_CALL( eigenv = cvGetMat( eigenv, &eigstub ));
if( CV_MAT_TYPE(src->type) != CV_8UC1 && CV_MAT_TYPE(src->type) != CV_32FC1 ||
CV_MAT_TYPE(eigenv->type) != CV_32FC1 )
CV_ERROR( CV_StsUnsupportedFormat, "Input must be 8uC1 or 32fC1, output must be 32fC1" );
if( !CV_ARE_SIZES_EQ( src, eigenv ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
CV_CALL( icvCornerEigenValsVecs( src, eigenv, block_size, aperture_size, ICV_HARRIS, k ));
__END__;
}
示例8: cvCornerEigenValsAndVecs
CV_IMPL void
cvCornerEigenValsAndVecs( const void* srcarr, void* eigenvarr,
int block_size, int aperture_size )
{
CV_FUNCNAME( "cvCornerEigenValsAndVecs" );
__BEGIN__;
CvMat stub, *src = (CvMat*)srcarr;
CvMat eigstub, *eigenv = (CvMat*)eigenvarr;
CV_CALL( src = cvGetMat( srcarr, &stub ));
CV_CALL( eigenv = cvGetMat( eigenv, &eigstub ));
if( CV_MAT_CN(eigenv->type)*eigenv->cols != src->cols*6 ||
eigenv->rows != src->rows )
CV_ERROR( CV_StsUnmatchedSizes, "Output array should be 6 times "
"wider than the input array and they should have the same height");
if( CV_MAT_TYPE(src->type) != CV_8UC1 && CV_MAT_TYPE(src->type) != CV_32FC1 ||
CV_MAT_TYPE(eigenv->type) != CV_32FC1 )
CV_ERROR( CV_StsUnsupportedFormat, "Input must be 8uC1 or 32fC1, output must be 32fC1" );
CV_CALL( icvCornerEigenValsVecs( src, eigenv, block_size, aperture_size, ICV_EIGENVALSVECS ));
__END__;
}
示例9: icvConvertIntToDecimal
void icvConvertIntToDecimal(const int ndigits, CvMat * src, CvMat * dst)
{
const int nsamples = src->rows;
const int nnumbers = src->cols;
assert(dst->rows==nsamples);
assert(CV_MAT_TYPE(src->type)==CV_32S);
assert(CV_MAT_TYPE(dst->type)==CV_32F);
CvMat * values = cvCreateMat(ndigits,10,CV_32F);
int stepsize = ndigits*10*sizeof(float);
for (int ii=0;ii<nsamples;ii++){
#if 0 // debug
fprintf(stderr,"number: ");
for (int jj=0;jj<nnumbers;jj++){
fprintf(stderr,"%d ",CV_MAT_ELEM(*src,int,ii,jj));
}
#endif
for (int jj=0;jj<nnumbers;jj++){
cvZero(values);
int number = CV_MAT_ELEM(*src,int,ii,jj);
for (int kk=0;kk<ndigits;kk++){
int pos = cvFloor((number%int(pow(10.f,kk+1)))/pow(10.f,kk));
CV_MAT_ELEM(*values,float,kk,pos)=1;
}
memcpy(dst->data.ptr+stepsize*(nnumbers*ii+jj),values->data.ptr,stepsize);
}
#if 0 // debug
fprintf(stderr,"\noutput:\n");
cvPrintf(stderr,"%.0f ",dst,cvRect(0,ii,dst->cols,1));
#endif
}
cvReleaseMat(&values);
}
示例10: cvSolvePoly
void cvSolvePoly(const CvMat* a, CvMat *r, int maxiter, int fig) {
int m = a->rows * a->cols;
int n = r->rows * r->cols;
__BEGIN__;
CV_FUNCNAME("cvSolvePoly");
if (CV_MAT_TYPE(a->type) != CV_32FC1 &&
CV_MAT_TYPE(a->type) != CV_64FC1)
CV_ERROR(CV_StsUnsupportedFormat, "coeffs must be either CV_32FC1 or CV_64FC1");
if (CV_MAT_TYPE(r->type) != CV_32FC2 &&
CV_MAT_TYPE(r->type) != CV_64FC2)
CV_ERROR(CV_StsUnsupportedFormat, "roots must be either CV_32FC2 or CV_64FC2");
if (CV_MAT_DEPTH(a->type) != CV_MAT_DEPTH(r->type))
CV_ERROR(CV_StsUnmatchedFormats, "coeffs and roots must have same depth");
if (m - 1 != n)
CV_ERROR(CV_StsUnmatchedFormats, "must have n + 1 coefficients");
switch (CV_MAT_DEPTH(a->type)) {
case CV_32F:
icvFindPolynomialRoots(a->data.fl, r->data.fl, n, maxiter, fig);
break;
case CV_64F:
icvFindPolynomialRoots(a->data.db, r->data.db, n, maxiter, fig);
break;
}
__END__;
}
示例11: cvBoundingRect
/* Calculates bounding rectagnle of a point set or retrieves already calculated */
CV_IMPL CvRect
cvBoundingRect( CvArr* array, int update )
{
CvRect rect = { 0, 0, 0, 0 };
CvContour contour_header;
CvSeq* ptseq = 0;
CvSeqBlock block;
CvMat stub, *mat = 0;
int calculate = update;
if( CV_IS_SEQ( array ))
{
ptseq = (CvSeq*)array;
if( !CV_IS_SEQ_POINT_SET( ptseq ))
CV_Error( CV_StsBadArg, "Unsupported sequence type" );
if( ptseq->header_size < (int)sizeof(CvContour))
{
update = 0;
calculate = 1;
}
}
else
{
mat = cvGetMat( array, &stub );
if( CV_MAT_TYPE(mat->type) == CV_32SC2 ||
CV_MAT_TYPE(mat->type) == CV_32FC2 )
{
ptseq = cvPointSeqFromMat(CV_SEQ_KIND_GENERIC, mat, &contour_header, &block);
mat = 0;
}
else if( CV_MAT_TYPE(mat->type) != CV_8UC1 &&
CV_MAT_TYPE(mat->type) != CV_8SC1 )
CV_Error( CV_StsUnsupportedFormat,
"The image/matrix format is not supported by the function" );
update = 0;
calculate = 1;
}
if( !calculate )
return ((CvContour*)ptseq)->rect;
if( mat )
{
rect = cv::maskBoundingRect(cv::cvarrToMat(mat));
}
else if( ptseq->total )
{
cv::AutoBuffer<double> abuf;
rect = cv::pointSetBoundingRect(cv::cvarrToMat(ptseq, false, false, 0, &abuf));
}
if( update )
((CvContour*)ptseq)->rect = rect;
return rect;
}
示例12: cvNeumannBoundCond
CV_IMPL void cvNeumannBoundCond(const CvArr * srcarr,
CvArr * dstarr)
{
CV_FUNCNAME("cvNeumannBoundCond");
__BEGIN__;
CvMat sstub, *src;
CvMat dstub, *dst;
CvSize size;
int i, j;
float * ptr_src, * ptr_dst;
int iStep_src, iStep_dst;
CV_CALL( src = cvGetMat(srcarr, &sstub ));
CV_CALL( dst = cvGetMat(dstarr, &dstub ));
if( CV_MAT_TYPE(src->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( CV_MAT_TYPE(dst->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( !CV_ARE_SIZES_EQ(src, dst))
CV_ERROR( CV_StsUnmatchedSizes, "The input images must have the same size" );
size = cvGetMatSize( src );
cvCopy(src, dst);
ptr_src = src->data.fl;
iStep_src = src->step / sizeof(ptr_src[0]);
ptr_dst = dst->data.fl;
iStep_dst = dst->step / sizeof(ptr_dst[0]);
ptr_dst[0] = ptr_src[2+iStep_src*2];
//dst(0,0)=src(3,3)
ptr_dst[size.width-1] = ptr_src[size.width-3+iStep_src*2];
//dst(0,col-1)=src(3,col-3)
ptr_dst[iStep_dst*(size.height-1)] = ptr_src[2+iStep_src*(size.height-3)];
//dst(row-1,0)=src(row-3,3)
ptr_dst[size.width-1+iStep_dst*(size.height-1)] = ptr_src[size.width-3+iStep_dst*(size.height-3)];
//dst(row-1,col-1)=src(row-3,col-3)
for(i = 1; i < size.width-1; i++){
ptr_dst[i] = ptr_src[i+iStep_src*2];
ptr_dst[i+iStep_dst*(size.height-1)]=ptr_src[i+iStep_src*(size.height-3)];
}
for(j = 1; j < size.height-1; j++){
ptr_dst[iStep_dst*j] = ptr_src[2+iStep_src*j];
ptr_dst[size.width-1+iStep_dst*j]=ptr_src[size.width-3+iStep_src*j];
}
__END__;
}
示例13: cvCalS
CV_IMPL void cvCalS(const CvArr* srcarr,
CvArr* dstarr)
{
CV_FUNCNAME("cvCalS");
__BEGIN__;
CvMat sstub, *src;
CvMat dstub, *dst;
CvMat* src_dx=0, *src_dy=0;
CvSize size;
int i, j;
int iStep;
float* fPtr;
CV_CALL( src = cvGetMat(srcarr, &sstub ));
CV_CALL( dst = cvGetMat(dstarr, &dstub ));
if( CV_MAT_TYPE(src->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( CV_MAT_TYPE(dst->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( !CV_ARE_SIZES_EQ( src, dst ))
CV_ERROR( CV_StsUnmatchedSizes, "The input images must have the same size" );
size = cvGetMatSize( src );
src_dx = cvCreateMat(size.height, size.width, CV_32FC1 );
src_dy = cvCreateMat(size.height, size.width, CV_32FC1 );
cvSetZero(src_dx);
cvSetZero(src_dy);
iStep = dst->step / sizeof(fPtr[0]);
fPtr = dst->data.fl;
cvSobel(src, src_dx, 1, 0, 1);
cvSobel(src, src_dy, 0, 1, 1);
cvMul(src_dx, src_dx, src_dx, 0.25f*0.25f); //rescale gradient
cvMul(src_dy, src_dy, src_dy, 0.25f*0.25f); //rescale gradient
cvAdd(src_dx, src_dy, dst);
for(j=0; j<size.height; j++){
for (i=0; i<size.width; i++)
fPtr[i+iStep*j] = sqrt(fPtr[i+iStep*j])+SMALLNUM;
}
cvReleaseMat(&src_dx);
cvReleaseMat(&src_dy);
__END__;
}
示例14: cvCurvature
CV_IMPL void cvCurvature(const CvArr* srcarr_x,
const CvArr* srcarr_y,
CvArr* dstarr)
{
CV_FUNCNAME("cvCurvature");
__BEGIN__;
CvMat sstub_x, sstub_y, *src_x, *src_y;
CvMat dstub, *dst;
CvSize size;
CvMat *Nxx=0, *Nyy=0, *ones=0;
CV_CALL( src_x = cvGetMat(srcarr_x, &sstub_x ));
CV_CALL( src_y = cvGetMat(srcarr_y, &sstub_y ));
CV_CALL( dst = cvGetMat(dstarr, &dstub ));
if( CV_MAT_TYPE(src_x->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( CV_MAT_TYPE(src_y->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( CV_MAT_TYPE(dst->type) != CV_32FC1)
CV_ERROR( CV_StsUnsupportedFormat, "Only-32bit, 1-channel input images are supported" );
if( !CV_ARE_SIZES_EQ( src_x, src_y ))
CV_ERROR( CV_StsUnmatchedSizes, "The input images must have the same size" );
size = cvGetMatSize( src_x );
Nxx = cvCreateMat(size.height, size.width, CV_32FC1 );
Nyy = cvCreateMat(size.height, size.width, CV_32FC1 );
ones= cvCreateMat(size.height, size.width, CV_32FC1 );
cvSetZero(Nxx);
cvSetZero(Nyy);
cvSet(ones, cvScalar(1.0f));
cvSobel(src_x, Nxx, 1, 0, 1);
cvSobel(src_y, Nyy, 0, 1, 1);
cvMul(Nxx, ones, Nxx, 0.25f);
cvMul(Nyy, ones, Nyy, 0.25f);
cvAdd(Nxx, Nyy, dst);
cvReleaseMat(&Nxx);
cvReleaseMat(&Nyy);
cvReleaseMat(&ones);
__END__;
}
示例15: cvMatNDToMat
static Mat cvMatNDToMat(const CvMatND* m, bool copyData)
{
Mat thiz;
if( !m )
return thiz;
thiz.datastart = thiz.data = m->data.ptr;
thiz.flags |= CV_MAT_TYPE(m->type);
int _sizes[CV_MAX_DIM];
size_t _steps[CV_MAX_DIM];
int d = m->dims;
for( int i = 0; i < d; i++ )
{
_sizes[i] = m->dim[i].size;
_steps[i] = m->dim[i].step;
}
setSize(thiz, d, _sizes, _steps);
finalizeHdr(thiz);
if( copyData )
{
Mat temp(thiz);
thiz.release();
temp.copyTo(thiz);
}
return thiz;
}