MCPcopy Create free account
hub / github.com/creatale/node-dv / cvGet1D

Function cvGet1D

deps/opencv/modules/core/src/array.cpp:1910–1941  ·  view source on GitHub ↗

Returns specifed element of n-D array given linear index

Source from the content-addressed store, hash-verified

1908
1909// Returns specifed element of n-D array given linear index
1910CV_IMPL CvScalar
1911cvGet1D( const CvArr* arr, int idx )
1912{
1913 CvScalar scalar = {{0,0,0,0}};
1914 int type = 0;
1915 uchar* ptr;
1916
1917 if( CV_IS_MAT( arr ) && CV_IS_MAT_CONT( ((CvMat*)arr)->type ))
1918 {
1919 CvMat* mat = (CvMat*)arr;
1920
1921 type = CV_MAT_TYPE(mat->type);
1922 int pix_size = CV_ELEM_SIZE(type);
1923
1924 // the first part is mul-free sufficient check
1925 // that the index is within the matrix
1926 if( (unsigned)idx >= (unsigned)(mat->rows + mat->cols - 1) &&
1927 (unsigned)idx >= (unsigned)(mat->rows*mat->cols))
1928 CV_Error( CV_StsOutOfRange, "index is out of range" );
1929
1930 ptr = mat->data.ptr + (size_t)idx*pix_size;
1931 }
1932 else if( !CV_IS_SPARSE_MAT( arr ) || ((CvSparseMat*)arr)->dims > 1 )
1933 ptr = cvPtr1D( arr, idx, &type );
1934 else
1935 ptr = icvGetNodePtr( (CvSparseMat*)arr, &idx, &type, 0, 0 );
1936
1937 if( ptr )
1938 cvRawDataToScalar( ptr, type, &scalar );
1939
1940 return scalar;
1941}
1942
1943
1944// Returns specifed element of 2D array

Callers

nothing calls this directly

Calls 3

cvPtr1DFunction · 0.85
icvGetNodePtrFunction · 0.85
cvRawDataToScalarFunction · 0.85

Tested by

no test coverage detected