1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| // Returns specifed element of 2D array
CV_IMPL CvScalar
cvGet2D( const CvArr* arr, int y, int x )
{
CvScalar scalar = {{0,0,0,0}};
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 )
cvRawDataToScalar( ptr, type, &scalar );
return scalar;
} |
Partager