📄 cxarray.cpp
字号:
(unsigned)x >= (unsigned)width )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr += y*img->widthStep + x*pix_size;
if( _type )
{
int type = icvIplToCvDepth(img->depth);
if( type < 0 || (unsigned)(img->nChannels - 1) > 3 )
CV_ERROR( CV_StsUnsupportedFormat, "" );
*_type = CV_MAKETYPE( type, img->nChannels );
}
}
else if( CV_IS_MATND( arr ))
{
CvMatND* mat = (CvMatND*)arr;
if( mat->dims != 2 ||
(unsigned)y >= (unsigned)(mat->dim[0].size) ||
(unsigned)x >= (unsigned)(mat->dim[1].size) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr = mat->data.ptr + (size_t)y*mat->dim[0].step + x*mat->dim[1].step;
if( _type )
*_type = CV_MAT_TYPE(mat->type);
}
else if( CV_IS_SPARSE_MAT( arr ))
{
int idx[] = { y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, _type, 1, 0 );
}
else
{
CV_ERROR( CV_StsBadArg, "unrecognized or unsupported array type" );
}
__END__;
return ptr;
}
// Returns pointer to specified element of 3d array
CV_IMPL uchar*
cvPtr3D( const CvArr* arr, int z, int y, int x, int* _type )
{
uchar* ptr = 0;
CV_FUNCNAME( "cvPtr3D" );
__BEGIN__;
if( CV_IS_MATND( arr ))
{
CvMatND* mat = (CvMatND*)arr;
if( mat->dims != 3 ||
(unsigned)z >= (unsigned)(mat->dim[0].size) ||
(unsigned)y >= (unsigned)(mat->dim[1].size) ||
(unsigned)x >= (unsigned)(mat->dim[2].size) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr = mat->data.ptr + (size_t)z*mat->dim[0].step +
(size_t)y*mat->dim[1].step + x*mat->dim[2].step;
if( _type )
*_type = CV_MAT_TYPE(mat->type);
}
else if( CV_IS_SPARSE_MAT( arr ))
{
int idx[] = { z, y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, _type, 1, 0 );
}
else
{
CV_ERROR( CV_StsBadArg, "unrecognized or unsupported array type" );
}
__END__;
return ptr;
}
// Returns pointer to specified element of n-d array
CV_IMPL uchar*
cvPtrND( const CvArr* arr, const int* idx, int* _type,
int create_node, unsigned* precalc_hashval )
{
uchar* ptr = 0;
CV_FUNCNAME( "cvPtrND" );
__BEGIN__;
if( !idx )
CV_ERROR( CV_StsNullPtr, "NULL pointer to indices" );
if( CV_IS_SPARSE_MAT( arr ))
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx,
_type, create_node, precalc_hashval );
else if( CV_IS_MATND( arr ))
{
CvMatND* mat = (CvMatND*)arr;
int i;
ptr = mat->data.ptr;
for( i = 0; i < mat->dims; i++ )
{
if( (unsigned)idx[i] >= (unsigned)(mat->dim[i].size) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr += (size_t)idx[i]*mat->dim[i].step;
}
if( _type )
*_type = CV_MAT_TYPE(mat->type);
}
else if( CV_IS_MAT_HDR(arr) || CV_IS_IMAGE_HDR(arr) )
ptr = cvPtr2D( arr, idx[0], idx[1], _type );
else
CV_ERROR( CV_StsBadArg, "unrecognized or unsupported array type" );
__END__;
return ptr;
}
// Returns specifed element of n-D array given linear index
CV_IMPL CvScalar
cvGet1D( const CvArr* arr, int idx )
{
CvScalar scalar = {{0,0,0,0}};
CV_FUNCNAME( "cvGet1D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type ))
{
CvMat* mat = (CvMat*)arr;
type = CV_MAT_TYPE(mat->type);
int pix_size = CV_ELEM_SIZE(type);
// the first part is mul-free sufficient check
// that the index is within the matrix
if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) &&
(unsigned)idx >= (unsigned)(mat->rows*mat->cols))
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr = mat->data.ptr + (size_t)idx*pix_size;
}
else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 )
ptr = cvPtr1D( arr, idx, &type );
else
ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, 0, 0 );
cvRawDataToScalar( ptr, type, &scalar );
__END__;
return scalar;
}
// Returns specifed element of 2D array
CV_IMPL CvScalar
cvGet2D( const CvArr* arr, int y, int x )
{
CvScalar scalar = {{0,0,0,0}};
CV_FUNCNAME( "cvGet2D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ))
{
CvMat* mat = (CvMat*)arr;
if( (unsigned)y >= (unsigned)(mat->rows) ||
(unsigned)x >= (unsigned)(mat->cols) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
type = CV_MAT_TYPE(mat->type);
ptr = mat->data.ptr + (size_t)y*mat->step + x*CV_ELEM_SIZE(type);
}
else if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr2D( arr, y, x, &type );
else
{
int idx[] = { y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
}
cvRawDataToScalar( ptr, type, &scalar );
__END__;
return scalar;
}
// Returns specifed element of 3D array
CV_IMPL CvScalar
cvGet3D( const CvArr* arr, int z, int y, int x )
{
CvScalar scalar = {{0,0,0,0}};
/*CV_FUNCNAME( "cvGet3D" );*/
__BEGIN__;
int type = 0;
uchar* ptr;
if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr3D( arr, z, y, x, &type );
else
{
int idx[] = { z, y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
}
cvRawDataToScalar( ptr, type, &scalar );
__END__;
return scalar;
}
// Returns specifed element of nD array
CV_IMPL CvScalar
cvGetND( const CvArr* arr, const int* idx )
{
CvScalar scalar = {{0,0,0,0}};
/*CV_FUNCNAME( "cvGetND" );*/
__BEGIN__;
int type = 0;
uchar* ptr;
if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtrND( arr, idx, &type );
else
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
cvRawDataToScalar( ptr, type, &scalar );
__END__;
return scalar;
}
// Returns specifed element of n-D array given linear index
CV_IMPL double
cvGetReal1D( const CvArr* arr, int idx )
{
double value = 0;
CV_FUNCNAME( "cvGetReal1D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type ))
{
CvMat* mat = (CvMat*)arr;
type = CV_MAT_TYPE(mat->type);
int pix_size = CV_ELEM_SIZE(type);
// the first part is mul-free sufficient check
// that the index is within the matrix
if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) &&
(unsigned)idx >= (unsigned)(mat->rows*mat->cols))
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr = mat->data.ptr + (size_t)idx*pix_size;
}
else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 )
ptr = cvPtr1D( arr, idx, &type );
else
ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, 0, 0 );
if( ptr )
{
if( CV_MAT_CN( type ) > 1 )
CV_ERROR( CV_BadNumChannels, "cvGetReal* support only single-channel arrays" );
value = icvGetReal( ptr, type );
}
__END__;
return value;
}
// Returns specifed element of 2D array
CV_IMPL double
cvGetReal2D( const CvArr* arr, int y, int x )
{
double value = 0;
CV_FUNCNAME( "cvGetReal2D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ))
{
CvMat* mat = (CvMat*)arr;
if( (unsigned)y >= (unsigned)(mat->rows) ||
(unsigned)x >= (unsigned)(mat->cols) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
type = CV_MAT_TYPE(mat->type);
ptr = mat->data.ptr + (size_t)y*mat->step + x*CV_ELEM_SIZE(type);
}
else if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr2D( arr, y, x, &type );
else
{
int idx[] = { y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
}
if( ptr )
{
if( CV_MAT_CN( type ) > 1 )
CV_ERROR( CV_BadNumChannels, "cvGetReal* support only single-channel arrays" );
value = icvGetReal( ptr, type );
}
__END__;
return value;
}
// Returns specifed element of 3D array
CV_IMPL double
cvGetReal3D( const CvArr* arr, int z, int y, int x )
{
double value = 0;
CV_FUNCNAME( "cvGetReal3D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr3D( arr, z, y, x, &type );
else
{
int idx[] = { z, y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
}
if( ptr )
{
if( CV_MAT_CN( type ) > 1 )
CV_ERROR( CV_BadNumChannels, "cvGetReal* support only single-channel arrays" );
value = icvGetReal( ptr, type );
}
__END__;
return value;
}
// Returns specifed element of nD array
CV_IMPL double
cvGetRealND( const CvArr* arr, const int* idx )
{
double value = 0;
CV_FUNCNAME( "cvGetRealND" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtrND( arr, idx, &type );
else
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, 0, 0 );
if( ptr )
{
if( CV_MAT_CN( type ) > 1 )
CV_ERROR( CV_BadNumChannels, "cvGetReal* support only single-channel arrays" );
value = icvGetReal( ptr, type );
}
__END__;
return value;
}
// Assigns new value to specifed element of nD array given linear index
CV_IMPL void
cvSet1D( CvArr* arr, int idx, CvScalar scalar )
{
CV_FUNCNAME( "cvSet1D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type ))
{
CvMat* mat = (CvMat*)arr;
type = CV_MAT_TYPE(mat->type);
int pix_size = CV_ELEM_SIZE(type);
// the first part is mul-free sufficient check
// that the index is within the matrix
if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) &&
(unsigned)idx >= (unsigned)(mat->rows*mat->cols))
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
ptr = mat->data.ptr + (size_t)idx*pix_size;
}
else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 )
ptr = cvPtr1D( arr, idx, &type );
else
ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, -1, 0 );
cvScalarToRawData( &scalar, ptr, type );
__END__;
}
// Assigns new value to specifed element of 2D array
CV_IMPL void
cvSet2D( CvArr* arr, int y, int x, CvScalar scalar )
{
CV_FUNCNAME( "cvSet2D" );
__BEGIN__;
int type = 0;
uchar* ptr;
if( CV_IS_MAT( arr ))
{
CvMat* mat = (CvMat*)arr;
if( (unsigned)y >= (unsigned)(mat->rows) ||
(unsigned)x >= (unsigned)(mat->cols) )
CV_ERROR( CV_StsOutOfRange, "index is out of range" );
type = CV_MAT_TYPE(mat->type);
ptr = mat->data.ptr + (size_t)y*mat->step + x*CV_ELEM_SIZE(type);
}
else if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr2D( arr, y, x, &type );
else
{
int idx[] = { y, x };
ptr = icvGetNodePtr( (CvSparseMat*)arr, idx, &type, -1, 0 );
}
cvScalarToRawData( &scalar, ptr, type );
__END__;
}
// Assigns new value to specifed element of 3D array
CV_IMPL void
cvSet3D( CvArr* arr, int z, int y, int x, CvScalar scalar )
{
/*CV_FUNCNAME( "cvSet3D" );*/
__BEGIN__;
int type = 0;
uchar* ptr;
if( !CV_IS_SPARSE_MAT( arr ))
ptr = cvPtr3D( arr, z, y, x, &type );
else
{
int idx[] = { z,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -