📄 cvutils.cpp
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "_cv.h"
CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr,
CvContour* contour_header, CvSeqBlock* block )
{
CvSeq* contour = 0;
CV_FUNCNAME( "cvPointSeqFromMat" );
assert( arr != 0 && contour_header != 0 && block != 0 );
__BEGIN__;
int eltype;
CvMat* mat = (CvMat*)arr;
if( !CV_IS_MAT( mat ))
CV_ERROR( CV_StsBadArg, "Input array is not a valid matrix" );
eltype = CV_MAT_TYPE( mat->type );
if( eltype != CV_32SC2 && eltype != CV_32FC2 )
CV_ERROR( CV_StsUnsupportedFormat,
"The matrix can not be converted to point sequence because of "
"inappropriate element type" );
if( mat->width != 1 && mat->height != 1 || !CV_IS_MAT_CONT(mat->type))
CV_ERROR( CV_StsBadArg,
"The matrix converted to point sequence must be "
"1-dimensional and continuous" );
CV_CALL( cvMakeSeqHeaderForArray(
(seq_kind & (CV_SEQ_KIND_MASK|CV_SEQ_FLAG_CLOSED)) | eltype,
sizeof(CvContour), CV_ELEM_SIZE(eltype), mat->data.ptr,
mat->width*mat->height, (CvSeq*)contour_header, block ));
contour = (CvSeq*)contour_header;
__END__;
return contour;
}
typedef CvStatus (CV_STDCALL * CvCopyNonConstBorderFunc)(
const void*, int, CvSize, void*, int, CvSize, int, int );
typedef CvStatus (CV_STDCALL * CvCopyNonConstBorderFuncI)(
const void*, int, CvSize, CvSize, int, int );
icvCopyReplicateBorder_8u_C1R_t icvCopyReplicateBorder_8u_C1R_p = 0;
icvCopyReplicateBorder_16s_C1R_t icvCopyReplicateBorder_16s_C1R_p = 0;
icvCopyReplicateBorder_8u_C3R_t icvCopyReplicateBorder_8u_C3R_p = 0;
icvCopyReplicateBorder_32s_C1R_t icvCopyReplicateBorder_32s_C1R_p = 0;
icvCopyReplicateBorder_16s_C3R_t icvCopyReplicateBorder_16s_C3R_p = 0;
icvCopyReplicateBorder_16s_C4R_t icvCopyReplicateBorder_16s_C4R_p = 0;
icvCopyReplicateBorder_32s_C3R_t icvCopyReplicateBorder_32s_C3R_p = 0;
icvCopyReplicateBorder_32s_C4R_t icvCopyReplicateBorder_32s_C4R_p = 0;
icvCopyReplicateBorder_8u_C1IR_t icvCopyReplicateBorder_8u_C1IR_p = 0;
icvCopyReplicateBorder_16s_C1IR_t icvCopyReplicateBorder_16s_C1IR_p = 0;
icvCopyReplicateBorder_8u_C3IR_t icvCopyReplicateBorder_8u_C3IR_p = 0;
icvCopyReplicateBorder_32s_C1IR_t icvCopyReplicateBorder_32s_C1IR_p = 0;
icvCopyReplicateBorder_16s_C3IR_t icvCopyReplicateBorder_16s_C3IR_p = 0;
icvCopyReplicateBorder_16s_C4IR_t icvCopyReplicateBorder_16s_C4IR_p = 0;
icvCopyReplicateBorder_32s_C3IR_t icvCopyReplicateBorder_32s_C3IR_p = 0;
icvCopyReplicateBorder_32s_C4IR_t icvCopyReplicateBorder_32s_C4IR_p = 0;
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);
int i, j;
if( srcstep == dststep && dst + dststep*top + left*cn == src &&
icvCopyReplicateBorder_8u_C1IR_p )
{
CvCopyNonConstBorderFuncI ifunc =
cn == 1 ? icvCopyReplicateBorder_8u_C1IR_p :
cn == 2 ? icvCopyReplicateBorder_16s_C1IR_p :
cn == 3 ? icvCopyReplicateBorder_8u_C3IR_p :
cn == 4 ? icvCopyReplicateBorder_32s_C1IR_p :
cn == 6 ? icvCopyReplicateBorder_16s_C3IR_p :
cn == 8 ? icvCopyReplicateBorder_16s_C4IR_p :
cn == 12 ? icvCopyReplicateBorder_32s_C3IR_p :
cn == 16 ? icvCopyReplicateBorder_32s_C4IR_p : 0;
if( ifunc )
return ifunc( src, srcstep, srcroi, dstroi, top, left );
}
else if( icvCopyReplicateBorder_8u_C1R_p )
{
CvCopyNonConstBorderFunc func =
cn == 1 ? icvCopyReplicateBorder_8u_C1R_p :
cn == 2 ? icvCopyReplicateBorder_16s_C1R_p :
cn == 3 ? icvCopyReplicateBorder_8u_C3R_p :
cn == 4 ? icvCopyReplicateBorder_32s_C1R_p :
cn == 6 ? icvCopyReplicateBorder_16s_C3R_p :
cn == 8 ? icvCopyReplicateBorder_16s_C4R_p :
cn == 12 ? icvCopyReplicateBorder_32s_C3R_p :
cn == 16 ? icvCopyReplicateBorder_32s_C4R_p : 0;
if( func )
return func( src, srcstep, srcroi, dst, dststep, dstroi, top, left );
}
if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 )
{
const int* isrc = (const int*)src;
int* idst = (int*)dst;
cn /= isz;
srcstep /= isz;
dststep /= isz;
srcroi.width *= cn;
dstroi.width *= cn;
left *= cn;
for( i = 0; i < dstroi.height; i++, idst += dststep )
{
if( idst + left != isrc )
for( j = 0; j < srcroi.width; j++ )
idst[j + left] = isrc[j];
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 )
{
if( dst + left != src )
for( j = 0; j < srcroi.width; j++ )
dst[j + left] = src[j];
for( j = left - 1; j >= 0; j-- )
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;
}
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;
srcstep /= isz;
dststep /= isz;
int_mode = 1;
}
srcroi.width *= cn;
dstroi.width *= cn;
left *= cn;
tab_size = dstroi.width - srcroi.width;
tab = (int*)cvStackAlloc( tab_size*sizeof(tab[0]) );
if( srcroi.width == 1 )
{
for( k = 0; k < cn; k++ )
for( i = 0; i < tab_size; i += cn )
tab[i + k] = k + left;
}
else
{
j = dj = cn;
for( i = left - cn; i >= 0; 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;
}
j = srcroi.width - cn*2;
dj = -cn;
for( i = left; i < tab_size; j += 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 )
for( j = 0; j < srcroi.width; j++ )
idst[j + left] = isrc[j];
for( j = 0; i < left; j++ )
{
k = tab[j];
idst[j] = idst[k];
}
for( ; j < tab_size; j++ )
{
k = tab[j];
idst[j + srcroi.width] = idst[k];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -