|
|
@ -71,413 +71,164 @@ CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr, |
|
|
|
return (CvSeq*)contour_header; |
|
|
|
return (CvSeq*)contour_header; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
typedef CvStatus (CV_STDCALL * CvCopyNonConstBorderFunc)( |
|
|
|
static void copyMakeBorder_8u( const uchar* src, int srcstep, Size srcroi, |
|
|
|
const void*, int, CvSize, void*, int, CvSize, int, int ); |
|
|
|
uchar* dst, int dststep, Size dstroi, |
|
|
|
|
|
|
|
int top, int left, int cn, int borderType ) |
|
|
|
typedef CvStatus (CV_STDCALL * CvCopyNonConstBorderFuncI)( |
|
|
|
|
|
|
|
const void*, int, CvSize, CvSize, int, int ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CvStatus CV_STDCALL |
|
|
|
|
|
|
|
icvCopyReplicateBorder_8u( const uchar* src, int srcstep, CvSize srcroi, |
|
|
|
|
|
|
|
uchar* dst, int dststep, CvSize dstroi, |
|
|
|
|
|
|
|
int top, int left, int cn, const uchar* ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
const int isz = (int)sizeof(int); |
|
|
|
const int isz = (int)sizeof(int); |
|
|
|
int i, j; |
|
|
|
int i, j, k, elemSize = 1; |
|
|
|
|
|
|
|
bool intMode = false; |
|
|
|
|
|
|
|
|
|
|
|
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 ) |
|
|
|
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const int* isrc = (const int*)src; |
|
|
|
|
|
|
|
int* idst = (int*)dst; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cn /= isz; |
|
|
|
cn /= isz; |
|
|
|
srcstep /= isz; |
|
|
|
elemSize = isz; |
|
|
|
dststep /= isz; |
|
|
|
intMode = true; |
|
|
|
|
|
|
|
|
|
|
|
srcroi.width *= cn; |
|
|
|
|
|
|
|
dstroi.width *= cn; |
|
|
|
|
|
|
|
left *= cn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < dstroi.height; i++, idst += dststep ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( idst + left != isrc ) |
|
|
|
|
|
|
|
memcpy( idst + left, isrc, srcroi.width*sizeof(idst[0]) ); |
|
|
|
|
|
|
|
for( j = left - 1; j >= 0; j-- ) |
|
|
|
|
|
|
|
idst[j] = idst[j + cn]; |
|
|
|
|
|
|
|
for( j = left+srcroi.width; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
idst[j] = idst[j - cn]; |
|
|
|
|
|
|
|
if( i >= top && i < top + srcroi.height - 1 ) |
|
|
|
|
|
|
|
isrc += srcstep; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
srcroi.width *= cn; |
|
|
|
|
|
|
|
dstroi.width *= cn; |
|
|
|
|
|
|
|
left *= cn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < dstroi.height; i++, dst += dststep ) |
|
|
|
AutoBuffer<int> _tab((dstroi.width - srcroi.width)*cn); |
|
|
|
|
|
|
|
int* tab = _tab; |
|
|
|
|
|
|
|
int right = dstroi.width - srcroi.width - left; |
|
|
|
|
|
|
|
int bottom = dstroi.height - srcroi.height - top; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < left; i++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( dst + left != src ) |
|
|
|
j = borderInterpolate(i - left, srcroi.width, borderType)*cn; |
|
|
|
memcpy( dst + left, src, srcroi.width ); |
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
for( j = left - 1; j >= 0; j-- ) |
|
|
|
tab[i*cn + k] = j + k; |
|
|
|
dst[j] = dst[j + cn]; |
|
|
|
|
|
|
|
for( j = left+srcroi.width; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
dst[j] = dst[j - cn]; |
|
|
|
|
|
|
|
if( i >= top && i < top + srcroi.height - 1 ) |
|
|
|
|
|
|
|
src += srcstep; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return CV_OK; |
|
|
|
for( i = 0; i < right; i++ ) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CvStatus CV_STDCALL |
|
|
|
|
|
|
|
icvCopyReflect101Border_8u( const uchar* src, int srcstep, CvSize srcroi, |
|
|
|
|
|
|
|
uchar* dst, int dststep, CvSize dstroi, |
|
|
|
|
|
|
|
int top, int left, int cn ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const int isz = (int)sizeof(int); |
|
|
|
|
|
|
|
int i, j, k, t, dj, tab_size, int_mode = 0; |
|
|
|
|
|
|
|
const int* isrc = (const int*)src; |
|
|
|
|
|
|
|
int* idst = (int*)dst, *tab; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
cn /= isz; |
|
|
|
j = borderInterpolate(srcroi.width + i, srcroi.width, borderType)*cn; |
|
|
|
srcstep /= isz; |
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
dststep /= isz; |
|
|
|
tab[(i+left)*cn + k] = j + k; |
|
|
|
|
|
|
|
|
|
|
|
int_mode = 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
srcroi.width *= cn; |
|
|
|
srcroi.width *= cn; |
|
|
|
dstroi.width *= cn; |
|
|
|
dstroi.width *= cn; |
|
|
|
left *= cn; |
|
|
|
left *= cn; |
|
|
|
|
|
|
|
right *= cn; |
|
|
|
|
|
|
|
|
|
|
|
tab_size = dstroi.width - srcroi.width; |
|
|
|
uchar* dstInner = dst + (dststep*top + left)*elemSize; |
|
|
|
tab = (int*)cvStackAlloc( tab_size*sizeof(tab[0]) ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( srcroi.width == 1 ) |
|
|
|
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) |
|
|
|
{ |
|
|
|
|
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
|
|
|
|
for( i = 0; i < tab_size; i += cn ) |
|
|
|
|
|
|
|
tab[i + k] = k + left; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
j = dj = cn; |
|
|
|
if( dstInner != src ) |
|
|
|
for( i = left - cn; i >= 0; i -= cn ) |
|
|
|
memcpy(dstInner, src, srcroi.width*elemSize); |
|
|
|
{ |
|
|
|
|
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
|
|
|
|
tab[i + k] = j + k + left; |
|
|
|
|
|
|
|
if( (unsigned)(j += dj) >= (unsigned)srcroi.width ) |
|
|
|
|
|
|
|
j -= 2*dj, dj = -dj; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
j = srcroi.width - cn*2; |
|
|
|
if( intMode ) |
|
|
|
dj = -cn; |
|
|
|
|
|
|
|
for( i = left; i < tab_size; i += cn ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
|
|
|
|
tab[i + k] = j + k + left; |
|
|
|
|
|
|
|
if( (unsigned)(j += dj) >= (unsigned)srcroi.width ) |
|
|
|
|
|
|
|
j -= 2*dj, dj = -dj; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( int_mode ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
idst += top*dststep; |
|
|
|
|
|
|
|
for( i = 0; i < srcroi.height; i++, isrc += srcstep, idst += dststep ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if( idst + left != isrc ) |
|
|
|
const int* isrc = (int*)src; |
|
|
|
memcpy( idst + left, isrc, srcroi.width*sizeof(idst[0]) ); |
|
|
|
int* idstInner = (int*)dstInner; |
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
{ |
|
|
|
idstInner[j - left] = isrc[tab[j]]; |
|
|
|
k = tab[j];
|
|
|
|
for( j = 0; j < right; j++ ) |
|
|
|
idst[j] = idst[k]; |
|
|
|
idstInner[j + srcroi.width] = isrc[tab[j + left]]; |
|
|
|
} |
|
|
|
|
|
|
|
for( ; j < tab_size; j++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
k = tab[j]; |
|
|
|
|
|
|
|
idst[j + srcroi.width] = idst[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
isrc -= srcroi.height*srcstep; |
|
|
|
|
|
|
|
idst -= (top + srcroi.height)*dststep; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
dst += top*dststep; |
|
|
|
|
|
|
|
for( i = 0; i < srcroi.height; i++, src += srcstep, dst += dststep ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( dst + left != src ) |
|
|
|
|
|
|
|
memcpy( dst + left, src, srcroi.width ); |
|
|
|
|
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
{ |
|
|
|
dstInner[j - left] = src[tab[j]]; |
|
|
|
k = tab[j];
|
|
|
|
for( j = 0; j < right; j++ ) |
|
|
|
dst[j] = dst[k]; |
|
|
|
dstInner[j + srcroi.width] = src[tab[j + left]]; |
|
|
|
} |
|
|
|
|
|
|
|
for( ; j < tab_size; j++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
k = tab[j]; |
|
|
|
|
|
|
|
dst[j + srcroi.width] = dst[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
src -= srcroi.height*srcstep; |
|
|
|
|
|
|
|
dst -= (top + srcroi.height)*dststep; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for( t = 0; t < 2; t++ ) |
|
|
|
dstroi.width *= elemSize; |
|
|
|
{ |
|
|
|
dst += dststep*top; |
|
|
|
int i1, i2, di; |
|
|
|
|
|
|
|
if( t == 0 ) |
|
|
|
|
|
|
|
i1 = top-1, i2 = 0, di = -1, j = 1, dj = 1; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
i1 = top+srcroi.height, i2=dstroi.height, di = 1, j = srcroi.height-2, dj = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = i1; (di > 0 && i < i2) || (di < 0 && i > i2); i += di ) |
|
|
|
for( i = 0; i < top; i++ ) |
|
|
|
{ |
|
|
|
|
|
|
|
if( int_mode ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
const int* s = idst + i*dststep; |
|
|
|
j = borderInterpolate(i - top, srcroi.height, borderType); |
|
|
|
int* d = idst + (j+top)*dststep; |
|
|
|
memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width); |
|
|
|
for( k = 0; k < dstroi.width; k++ ) |
|
|
|
|
|
|
|
d[k] = s[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const uchar* s = dst + i*dststep; |
|
|
|
|
|
|
|
uchar* d = dst + (j+top)*dststep; |
|
|
|
|
|
|
|
for( k = 0; k < dstroi.width; k++ ) |
|
|
|
|
|
|
|
d[k] = s[k]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( (unsigned)(j += dj) >= (unsigned)srcroi.height ) |
|
|
|
for( i = 0; i < bottom; i++ ) |
|
|
|
j -= 2*dj, dj = -dj; |
|
|
|
{ |
|
|
|
} |
|
|
|
j = borderInterpolate(i + srcroi.height, srcroi.height, borderType); |
|
|
|
|
|
|
|
memcpy(dst + (i + srcroi.height)*dststep, dst + j*dststep, dstroi.width); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return CV_OK; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CvStatus CV_STDCALL |
|
|
|
static void copyMakeConstBorder_8u( const uchar* src, int srcstep, Size srcroi, |
|
|
|
icvCopyConstBorder_8u( const uchar* src, int srcstep, CvSize srcroi, |
|
|
|
uchar* dst, int dststep, Size dstroi, |
|
|
|
uchar* dst, int dststep, CvSize dstroi, |
|
|
|
|
|
|
|
int top, int left, int cn, const uchar* value ) |
|
|
|
int top, int left, int cn, const uchar* value ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const int isz = (int)sizeof(int); |
|
|
|
int i, j; |
|
|
|
int i, j, k; |
|
|
|
AutoBuffer<uchar> _constBuf(dstroi.width*cn); |
|
|
|
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst | (size_t)value) % isz == 0 ) |
|
|
|
uchar* constBuf = _constBuf; |
|
|
|
{ |
|
|
|
int right = dstroi.width - srcroi.width - left; |
|
|
|
const int* isrc = (const int*)src; |
|
|
|
int bottom = dstroi.height - srcroi.height - top; |
|
|
|
int* idst = (int*)dst; |
|
|
|
|
|
|
|
const int* ivalue = (const int*)value; |
|
|
|
|
|
|
|
int v0 = ivalue[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cn /= isz; |
|
|
|
|
|
|
|
srcstep /= isz; |
|
|
|
|
|
|
|
dststep /= isz; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srcroi.width *= cn; |
|
|
|
|
|
|
|
dstroi.width *= cn; |
|
|
|
|
|
|
|
left *= cn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( j = 1; j < cn; j++ ) |
|
|
|
|
|
|
|
if( ivalue[j] != ivalue[0] ) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( j == cn ) |
|
|
|
|
|
|
|
cn = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( dstroi.width <= 0 ) |
|
|
|
|
|
|
|
return CV_OK; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < dstroi.height; i++, idst += dststep ) |
|
|
|
for( i = 0; i < dstroi.width; i++ ) |
|
|
|
{ |
|
|
|
|
|
|
|
if( i < top || i >= top + srcroi.height ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( cn == 1 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
idst[j] = v0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
for( j = 0; j < cn; j++ ) |
|
|
|
for( j = 0; j < cn; j++ ) |
|
|
|
idst[j] = ivalue[j]; |
|
|
|
constBuf[i*cn + j] = value[j]; |
|
|
|
for( ; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
idst[j] = idst[j - cn]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( cn == 1 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
|
|
|
|
idst[j] = v0; |
|
|
|
|
|
|
|
for( j = srcroi.width + left; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
idst[j] = v0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < left; j += cn ) |
|
|
|
|
|
|
|
idst[j+k] = ivalue[k]; |
|
|
|
|
|
|
|
for( j = srcroi.width + left; j < dstroi.width; j += cn ) |
|
|
|
|
|
|
|
idst[j+k] = ivalue[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( idst + left != isrc ) |
|
|
|
|
|
|
|
for( j = 0; j < srcroi.width; j++ ) |
|
|
|
|
|
|
|
idst[j + left] = isrc[j]; |
|
|
|
|
|
|
|
isrc += srcstep; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uchar v0 = value[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
srcroi.width *= cn; |
|
|
|
srcroi.width *= cn; |
|
|
|
dstroi.width *= cn; |
|
|
|
dstroi.width *= cn; |
|
|
|
left *= cn; |
|
|
|
left *= cn; |
|
|
|
|
|
|
|
right *= cn; |
|
|
|
|
|
|
|
|
|
|
|
for( j = 1; j < cn; j++ ) |
|
|
|
uchar* dstInner = dst + dststep*top + left; |
|
|
|
if( value[j] != value[0] ) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( j == cn ) |
|
|
|
for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) |
|
|
|
cn = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( dstroi.width <= 0 ) |
|
|
|
|
|
|
|
return CV_OK; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < dstroi.height; i++, dst += dststep ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( i < top || i >= top + srcroi.height ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if( cn == 1 ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
for( j = 0; j < dstroi.width; j++ ) |
|
|
|
if( dstInner != src ) |
|
|
|
dst[j] = v0; |
|
|
|
memcpy( dstInner, src, srcroi.width ); |
|
|
|
} |
|
|
|
memcpy( dstInner - left, constBuf, left ); |
|
|
|
else |
|
|
|
memcpy( dstInner + srcroi.width, constBuf + left, right ); |
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < cn; j++ ) |
|
|
|
|
|
|
|
dst[j] = value[j]; |
|
|
|
|
|
|
|
for( ; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
dst[j] = dst[j - cn]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( cn == 1 ) |
|
|
|
dst += dststep*top; |
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < left; j++ ) |
|
|
|
|
|
|
|
dst[j] = v0; |
|
|
|
|
|
|
|
for( j = srcroi.width + left; j < dstroi.width; j++ ) |
|
|
|
|
|
|
|
dst[j] = v0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( k = 0; k < cn; k++ ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for( j = 0; j < left; j += cn ) |
|
|
|
|
|
|
|
dst[j+k] = value[k]; |
|
|
|
|
|
|
|
for( j = srcroi.width + left; j < dstroi.width; j += cn ) |
|
|
|
|
|
|
|
dst[j+k] = value[k]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( dst + left != src ) |
|
|
|
for( i = 0; i < top; i++ ) |
|
|
|
for( j = 0; j < srcroi.width; j++ ) |
|
|
|
memcpy(dst + (i - top)*dststep, constBuf, dstroi.width); |
|
|
|
dst[j + left] = src[j]; |
|
|
|
|
|
|
|
src += srcstep; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return CV_OK; |
|
|
|
for( i = 0; i < bottom; i++ ) |
|
|
|
|
|
|
|
memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CV_IMPL void |
|
|
|
void copyMakeBorder( const Mat& src, Mat& dst, int top, int bottom, |
|
|
|
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset, |
|
|
|
int left, int right, int borderType, const Scalar& value ) |
|
|
|
int bordertype, CvScalar value ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
CvMat srcstub, *src = (CvMat*)srcarr; |
|
|
|
CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 ); |
|
|
|
CvMat dststub, *dst = (CvMat*)dstarr; |
|
|
|
|
|
|
|
CvSize srcsize, dstsize; |
|
|
|
dst.create( src.rows + top + bottom, src.cols + left + right, src.type() ); |
|
|
|
int srcstep, dststep; |
|
|
|
if( borderType != BORDER_CONSTANT ) |
|
|
|
int pix_size, type; |
|
|
|
copyMakeBorder_8u( src.data, src.step, src.size(), |
|
|
|
|
|
|
|
dst.data, dst.step, dst.size(), |
|
|
|
if( !CV_IS_MAT(src) ) |
|
|
|
top, left, src.elemSize(), borderType ); |
|
|
|
src = cvGetMat( src, &srcstub ); |
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
if( !CV_IS_MAT(dst) )
|
|
|
|
|
|
|
|
dst = cvGetMat( dst, &dststub ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( offset.x < 0 || offset.y < 0 ) |
|
|
|
|
|
|
|
CV_Error( CV_StsOutOfRange, "Offset (left/top border width) is negative" ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( src->rows + offset.y > dst->rows || src->cols + offset.x > dst->cols ) |
|
|
|
|
|
|
|
CV_Error( CV_StsBadSize, "Source array is too big or destination array is too small" ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !CV_ARE_TYPES_EQ( src, dst )) |
|
|
|
|
|
|
|
CV_Error( CV_StsUnmatchedFormats, "" ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type = CV_MAT_TYPE(src->type); |
|
|
|
|
|
|
|
pix_size = CV_ELEM_SIZE(type); |
|
|
|
|
|
|
|
srcsize = cvGetMatSize(src); |
|
|
|
|
|
|
|
dstsize = cvGetMatSize(dst); |
|
|
|
|
|
|
|
srcstep = src->step; |
|
|
|
|
|
|
|
dststep = dst->step; |
|
|
|
|
|
|
|
if( srcstep == 0 ) |
|
|
|
|
|
|
|
srcstep = CV_STUB_STEP; |
|
|
|
|
|
|
|
if( dststep == 0 ) |
|
|
|
|
|
|
|
dststep = CV_STUB_STEP; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bordertype &= 15; |
|
|
|
|
|
|
|
if( bordertype == IPL_BORDER_REPLICATE ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
icvCopyReplicateBorder_8u( src->data.ptr, srcstep, srcsize, |
|
|
|
|
|
|
|
dst->data.ptr, dststep, dstsize, |
|
|
|
|
|
|
|
offset.y, offset.x, pix_size ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if( bordertype == IPL_BORDER_REFLECT_101 ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
icvCopyReflect101Border_8u( src->data.ptr, srcstep, srcsize, |
|
|
|
|
|
|
|
dst->data.ptr, dststep, dstsize, |
|
|
|
|
|
|
|
offset.y, offset.x, pix_size ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if( bordertype == IPL_BORDER_CONSTANT ) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
double buf[4]; |
|
|
|
double buf[4]; |
|
|
|
cvScalarToRawData( &value, buf, src->type, 0 ); |
|
|
|
scalarToRawData(value, buf, src.type()); |
|
|
|
icvCopyConstBorder_8u( src->data.ptr, srcstep, srcsize, |
|
|
|
copyMakeConstBorder_8u( src.data, src.step, src.size(), |
|
|
|
dst->data.ptr, dststep, dstsize, |
|
|
|
dst.data, dst.step, dst.size(), |
|
|
|
offset.y, offset.x, pix_size, (uchar*)buf ); |
|
|
|
top, left, src.elemSize(), (uchar*)buf ); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
CV_Error( CV_StsBadFlag, "Unknown/unsupported border type" ); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void copyMakeBorder( const Mat& src, Mat& dst, int top, int bottom, |
|
|
|
|
|
|
|
int left, int right, int borderType, const Scalar& value ) |
|
|
|
CV_IMPL void |
|
|
|
|
|
|
|
cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset, |
|
|
|
|
|
|
|
int borderType, CvScalar value ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
dst.create( src.rows + top + bottom, src.cols + left + right, src.type() ); |
|
|
|
cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr); |
|
|
|
CvMat _src = src, _dst = dst; |
|
|
|
int left = offset.x, right = dst.cols - src.cols - left; |
|
|
|
cvCopyMakeBorder( &_src, &_dst, Point(left, top), borderType, value ); |
|
|
|
int top = offset.y, bottom = dst.rows - src.rows - top; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CV_Assert( dst.type() == src.type() ); |
|
|
|
|
|
|
|
cv::copyMakeBorder( src, dst, top, bottom, left, right, borderType, value ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* End of file. */ |
|
|
|
/* End of file. */ |
|
|
|