cverror.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 535 行 · 第 1/2 页
SVN-BASE
535 行
case CV_StsOutOfRange : return "One of arguments\' values is out of range";
case CV_StsUnsupportedFormat : return "Unsupported format or combination of formats";
case CV_BadCOI : return "Input COI is not supported";
case CV_BadNumChannels : return "Bad number of channels";
case CV_StsBadFlag : return "Bad flag (parameter or structure field)";
case CV_StsBadPoint : return "Bad parameter of type CvPoint";
};
sprintf(buf, "Unknown %s code %d", status >= 0 ? "status":"error", status);
return buf;
}
CV_IMPL int cvGetErrMode(void)
{
return icvGetContext()->CVErrMode;
}
CV_IMPL void cvSetErrMode( int mode )
{
icvGetContext()->CVErrMode = mode;
}
CV_IMPL CVStatus cvGetErrStatus()
{
return icvGetContext()->CVLastStatus;
}
CV_IMPL void cvSetErrStatus(CVStatus status)
{
icvGetContext()->CVLastStatus = status;
}
/******************** Implementation of profiling stuff *********************/
/* initial assignment of profiling functions */
CvStartProfileFunc p_cvStartProfile = cvStartProfile;
CvEndProfileFunc p_cvEndProfile = cvEndProfile;
CV_IMPL void cvSetProfile( void (CV_CDECL *startprofile_f)(const char*, const char*, int),
void (CV_CDECL *endprofile_f)(const char*, int))
{
p_cvStartProfile = startprofile_f;
p_cvEndProfile = endprofile_f;
}
CV_IMPL void cvRemoveProfile()
{
p_cvStartProfile = cvStartProfile;
p_cvEndProfile = cvEndProfile;
}
/* default implementation of cvStartProfile & cvEndProfile */
void CV_CDECL cvStartProfile(const char* call, const char* file, int line )
{
#ifdef _CV_COMPILE_PROFILE_
if( p_cvStartProfile != cvStartProfile )
{
p_cvStartProfile( call, file, line );
}
/* default implementation */
CvContext* context = icvGetContext();
/* add record to stack */
assert( context->CVStackCapacity >= context->CVStackSize );
if( context->CVStackCapacity == context->CVStackSize )
{
/* increase stack */
context->CVStackCapacity += 100;
context->CVStack = (CvStackRecord*)realloc( context->CVStack,
(context->CVStackCapacity) * sizeof(CvStackRecord) );
}
CvStackRecord* rec = &context->CVStack[context->CVStackSize];
rec->file = file;
rec->line = line;
context->CVStackSize++;
#else
/* avoid warning "unreferenced value" */
if( call||file||line) {}
assert(0);
#endif
};
CV_IMPL void cvEndProfile( const char* file, int line )
{
#ifdef _CV_COMPILE_PROFILE_
CvContext* context = icvGetContext();
if( p_cvEndProfile != cvEndProfile )
{
p_cvEndProfile( file, line );
}
/* default implementation */
context->CVStackSize--;
#else
/* avoid warning "unreferenced value" */
if( file||line) {}
assert(0);
#endif
};
CV_IMPL CVStatus cvError( CVStatus code, const char* funcName,
const char* msg, const char* file, int line )
{
CvContext* context = icvGetContext();
if ((code!=CV_StsBackTrace) && (code!=CV_StsAutoTrace))
cvSetErrStatus(code);
if (code == CV_StsOk)
return CV_StsOk;
#ifdef _CV_COMPILE_PROFILE_
int i;
char message[4096] = "";
/* copy input message */
strcpy( message, msg );
/* append stack info */
strcat( message, "\nStack\n{" );
char* mes = message + strlen(message);
for( i = 0; i < context->CVStackSize; i++ )
{
i ? 0 : sprintf( mes,"\n" ), mes += strlen(mes);
CvStackRecord* rec = &(context->CVStack[i]);
sprintf( mes, " %s line %d\n", rec->file, rec->line );
mes += strlen(mes);
}
strcat( message, "}\n" );
context->CVErrorFunc( code, funcName, message, file, line );
#else
context->CVErrorFunc( code, funcName, msg, file, line );
#endif
return code;
};
CV_IMPL void cvGetCallStack(CvStackRecord** stack, int* size)
{
CvContext* context = icvGetContext();
*stack = context->CVStack;
*size = context->CVStackSize;
}
/******************** End of implementation of profiling stuff *********************/
/**********************DllMain********************************/
#ifdef CV_DLL
#ifdef WIN32
BOOL WINAPI DllMain( HINSTANCE /*hinstDLL*/, /* DLL module handle */
DWORD fdwReason, /* reason called */
LPVOID /*lpvReserved*/) /* reserved */
{
CvContext *pContext;
/// Note the actual size of the structure is larger.
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_TlsIndex = TlsAlloc();
if( g_TlsIndex == TLS_OUT_OF_INDEXES ) return FALSE;
/* No break: Initialize the index for first thread. */
/* The attached process creates a new thread. */
case DLL_THREAD_ATTACH:
pContext = icvCreateContext();
if( pContext == NULL)
return FALSE;
TlsSetValue( g_TlsIndex, (LPVOID)pContext );
break;
case DLL_THREAD_DETACH:
if( g_TlsIndex != TLS_OUT_OF_INDEXES )
{
pContext = (CvContext*)TlsGetValue( g_TlsIndex );
if( pContext != NULL )
{
icvDestroyContext( pContext );
}
}
break;
case DLL_PROCESS_DETACH:
if( g_TlsIndex != TLS_OUT_OF_INDEXES ) {
pContext = (CvContext*)TlsGetValue( g_TlsIndex );
if( pContext != NULL )
{
icvDestroyContext( pContext );
}
TlsFree( g_TlsIndex );
}
break;
default:
break;
}
return TRUE;
}
#else
/* POSIX pthread */
/* function - destructor of thread */
void icvPthreadDestructor(void* key_val)
{
CvContext* context = (CvContext*) key_val;
icvDestroyContext( context );
}
int pthrerr = pthread_key_create( &g_TlsIndex, icvPthreadDestructor );
#endif
#endif
/* function, which converts CvStatus to CVStatus */
IPCVAPI_IMPL( CVStatus, icvErrorFromStatus, ( CvStatus status ) )
{
switch (status)
{
case CV_BADSIZE_ERR : return CV_StsBadSize; //bad parameter of type CvSize
case CV_NULLPTR_ERR : return CV_StsNullPtr;
case CV_DIV_BY_ZERO_ERR : return CV_StsDivByZero;
case CV_BADSTEP_ERR : return CV_BadStep ;
case CV_OUTOFMEM_ERR : return CV_StsNoMem;
case CV_BADARG_ERR : return CV_StsBadArg;
case CV_NOTDEFINED_ERR : return CV_StsError; //unknown/undefined err
case CV_INPLACE_NOT_SUPPORTED_ERR: return CV_StsInplaceNotSupported;
case CV_NOTFOUND_ERR : return CV_StsObjectNotFound;
case CV_BADCONVERGENCE_ERR: return CV_StsNoConv;
case CV_BADDEPTH_ERR : return CV_BadDepth;
case CV_UNMATCHED_FORMATS_ERR : return CV_StsUnmatchedFormats;
case CV_UNSUPPORTED_COI_ERR : return CV_BadCOI;
case CV_UNSUPPORTED_CHANNELS_ERR : return CV_BadNumChannels;
case CV_BADFLAG_ERR : return CV_StsBadFlag;//used when bad flag CV_ ..something
case CV_BADRANGE_ERR : return CV_StsBadArg; //used everywhere
case CV_BADCOEF_ERR :return CV_StsBadArg; //used everywhere
case CV_BADFACTOR_ERR:return CV_StsBadArg; //used everywhere
case CV_BADPOINT_ERR :return CV_StsBadPoint;
default: assert(0); return CV_StsError;
}
}
/* End of file */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?