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

Function cvRange

deps/opencv/modules/core/src/matrix.cpp:3000–3060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2998
2999
3000CV_IMPL CvArr*
3001cvRange( CvArr* arr, double start, double end )
3002{
3003 int ok = 0;
3004
3005 CvMat stub, *mat = (CvMat*)arr;
3006 double delta;
3007 int type, step;
3008 double val = start;
3009 int i, j;
3010 int rows, cols;
3011
3012 if( !CV_IS_MAT(mat) )
3013 mat = cvGetMat( mat, &stub);
3014
3015 rows = mat->rows;
3016 cols = mat->cols;
3017 type = CV_MAT_TYPE(mat->type);
3018 delta = (end-start)/(rows*cols);
3019
3020 if( CV_IS_MAT_CONT(mat->type) )
3021 {
3022 cols *= rows;
3023 rows = 1;
3024 step = 1;
3025 }
3026 else
3027 step = mat->step / CV_ELEM_SIZE(type);
3028
3029 if( type == CV_32SC1 )
3030 {
3031 int* idata = mat->data.i;
3032 int ival = cvRound(val), idelta = cvRound(delta);
3033
3034 if( fabs(val - ival) < DBL_EPSILON &&
3035 fabs(delta - idelta) < DBL_EPSILON )
3036 {
3037 for( i = 0; i < rows; i++, idata += step )
3038 for( j = 0; j < cols; j++, ival += idelta )
3039 idata[j] = ival;
3040 }
3041 else
3042 {
3043 for( i = 0; i < rows; i++, idata += step )
3044 for( j = 0; j < cols; j++, val += delta )
3045 idata[j] = cvRound(val);
3046 }
3047 }
3048 else if( type == CV_32FC1 )
3049 {
3050 float* fdata = mat->data.fl;
3051 for( i = 0; i < rows; i++, fdata += step )
3052 for( j = 0; j < cols; j++, val += delta )
3053 fdata[j] = (float)val;
3054 }
3055 else
3056 CV_Error( CV_StsUnsupportedFormat, "The function only supports 32sC1 and 32fC1 datatypes" );
3057

Callers

nothing calls this directly

Calls 2

cvGetMatFunction · 0.85
cvRoundFunction · 0.85

Tested by

no test coverage detected