Merge pull request #26101 from mshabunin:cpp-error-ts

C-API cleanup: moved cvErrorStr to new interface, minor ts changes #26101

Merge with opencv/opencv_contrib#3786

**Note:** `toString` might be too generic name (even though it is in `cv::Error::` namespace), another variant is `codeToString` (we have `typeToString` and `depthToString` in check.hpp).

**Note:** _ts_ module seem to have no other C API usage except for `ArrayTest` class which requires refactoring.
pull/26106/head
Maksim Shabunin 6 months ago committed by GitHub
parent babc669dba
commit f73560293f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 38
      modules/3d/test/test_homography.cpp
  2. 21
      modules/calib/src/circlesgrid.cpp
  3. 53
      modules/core/include/opencv2/core.hpp
  4. 243
      modules/core/include/opencv2/core/base.hpp
  5. 4
      modules/core/include/opencv2/core/check.hpp
  6. 14
      modules/core/include/opencv2/core/core_c.h
  7. 239
      modules/core/include/opencv2/core/exception.hpp
  8. 76
      modules/core/include/opencv2/core/fwddecl.hpp
  9. 2
      modules/core/include/opencv2/core/hal/intrin_rvv_scalable.hpp
  10. 14
      modules/core/src/array.cpp
  11. 123
      modules/core/src/system.cpp
  12. 8
      modules/core/test/test_countnonzero.cpp
  13. 22
      modules/core/test/test_eigen.cpp
  14. 12
      modules/highgui/src/window_winrt.cpp
  15. 2
      modules/imgcodecs/src/bitstrm.hpp
  16. 2
      modules/python/src2/cv2.cpp
  17. 4
      modules/stitching/src/seam_finders.cpp
  18. 9
      modules/ts/src/ts.cpp
  19. 2
      modules/video/src/tracking/detail/tracker_mil_model.cpp
  20. 2
      modules/video/src/tracking/detail/tracker_model.cpp

@ -46,12 +46,6 @@
namespace opencv_test { namespace {
#define CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE 1
#define CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF 2
#define CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF 3
#define CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK 4
#define CALIB3D_HOMOGRAPHY_ERROR_RANSAC_DIFF 5
#define MESSAGE_MATRIX_SIZE "Homography matrix must have 3*3 sizes."
#define MESSAGE_MATRIX_DIFF "Accuracy of homography transformation matrix less than required."
#define MESSAGE_REPROJ_DIFF_1 "Reprojection error for current pair of points more than required."
@ -297,7 +291,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_size(H_res_64[j]))
{
print_information_1(j, N, method, H_res_64[j]);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_SIZE);
return;
}
@ -307,7 +301,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff))
{
print_information_2(j, N, method, H_64, H_res_64[j], k, diff);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_DIFF);
return;
}
}
@ -330,7 +324,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_size(H_res_64[j]))
{
print_information_1(j, N, method, H_res_64[j]);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_SIZE);
return;
}
@ -338,7 +332,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_diff(H_64, H_res_64[j], NORM_TYPE[k], diff))
{
print_information_2(j, N, method, H_64, H_res_64[j], k, diff);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_DIFF, MESSAGE_MATRIX_DIFF);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_DIFF);
return;
}
@ -350,9 +344,9 @@ TEST(Calib3d_Homography, accuracy)
switch (code)
{
case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }
case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_2); break; }
case 3: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }
case 1: { CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_1); break; }
case 2: { CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_2); break; }
case 3: { CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_3); break; }
default: break;
}
@ -400,7 +394,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_size(H_res_64[j]))
{
print_information_1(j, N, method, H_res_64[j]);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_SIZE);
return;
}
@ -424,7 +418,7 @@ TEST(Calib3d_Homography, accuracy)
if (cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]) > max_2diff)
{
print_information_4(method, j, N, k, l, cv::norm(tmp_mat_3d, dst_mat_3d.col(k), NORM_TYPE[l]) - cv::norm(noise_2d.col(k), NORM_TYPE[l]));
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_1);
CV_Error(cv::Error::StsError, MESSAGE_REPROJ_DIFF_1);
return;
}
@ -434,7 +428,7 @@ TEST(Calib3d_Homography, accuracy)
if (cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]) > max_diff)
{
print_information_5(method, j, N, l, cv::norm(dst_res_3d, dst_mat_3d, NORM_TYPE[l]) - cv::norm(noise_2d, NORM_TYPE[l]));
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_REPROJ_DIFF, MESSAGE_REPROJ_DIFF_2);
CV_Error(cv::Error::StsError, MESSAGE_REPROJ_DIFF_2);
return;
}
@ -457,7 +451,7 @@ TEST(Calib3d_Homography, accuracy)
if (!check_matrix_size(H_res_64[j]))
{
print_information_1(j, N, method, H_res_64[j]);
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_MATRIX_SIZE, MESSAGE_MATRIX_SIZE);
CV_Error(cv::Error::StsError, MESSAGE_MATRIX_SIZE);
return;
}
@ -469,8 +463,8 @@ TEST(Calib3d_Homography, accuracy)
switch (code)
{
case 1: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_1); break; }
case 2: { CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_3); break; }
case 1: { CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_1); break; }
case 2: { CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_3); break; }
default: break;
}
@ -498,14 +492,14 @@ TEST(Calib3d_Homography, accuracy)
if (mask_res[j].at<bool>(k, 0) != (diff <= reproj_threshold))
{
print_information_6(method, j, N, k, diff, mask_res[j].at<bool>(k, 0));
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_4);
CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_4);
return;
}
if (mask.at<bool>(k, 0) && !mask_res[j].at<bool>(k, 0))
{
print_information_7(method, j, N, k, diff, mask.at<bool>(k, 0), mask_res[j].at<bool>(k, 0));
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_MASK, MESSAGE_RANSAC_MASK_5);
CV_Error(cv::Error::StsError, MESSAGE_RANSAC_MASK_5);
return;
}
@ -525,7 +519,7 @@ TEST(Calib3d_Homography, accuracy)
if (diff - cv::norm(noise_2d, NORM_TYPE[l]) > max_2diff)
{
print_information_8(method, j, N, k, l, diff - cv::norm(noise_2d, NORM_TYPE[l]));
CV_Error(CALIB3D_HOMOGRAPHY_ERROR_RANSAC_DIFF, MESSAGE_RANSAC_DIFF);
CV_Error(cv::Error::StsError, MESSAGE_RANSAC_DIFF);
return;
}
}

@ -647,7 +647,6 @@ bool CirclesGridFinder::findHoles()
CV_Error(Error::StsBadArg, "Unknown pattern type");
}
return (isDetectionCorrect());
//CV_Error( 0, "Detection is not correct" );
}
void CirclesGridFinder::rng2gridGraph(Graph &rng, std::vector<cv::Point2f> &vectors) const
@ -1006,14 +1005,14 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc
if (aboveConfidence >= belowConfidence)
{
if (!areCentersNew(above, holes))
CV_Error( 0, "Centers are not new" );
CV_Error( cv::Error::StsError, "Centers are not new" );
holes.insert(holes.begin(), above);
}
else
{
if (!areCentersNew(below, holes))
CV_Error( 0, "Centers are not new" );
CV_Error( cv::Error::StsError, "Centers are not new" );
holes.insert(holes.end(), below);
}
@ -1023,7 +1022,7 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc
if (aboveConfidence >= belowConfidence)
{
if (!areCentersNew(above, holes))
CV_Error( 0, "Centers are not new" );
CV_Error( cv::Error::StsError, "Centers are not new" );
for (size_t i = 0; i < holes.size(); i++)
{
@ -1033,7 +1032,7 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc
else
{
if (!areCentersNew(below, holes))
CV_Error( 0, "Centers are not new" );
CV_Error( cv::Error::StsError, "Centers are not new" );
for (size_t i = 0; i < holes.size(); i++)
{
@ -1102,7 +1101,7 @@ void CirclesGridFinder::addHolesByGraph(const std::vector<Graph> &basisGraphs, b
void CirclesGridFinder::filterOutliersByDensity(const std::vector<Point2f> &samples, std::vector<Point2f> &filteredSamples)
{
if (samples.empty())
CV_Error( 0, "samples is empty" );
CV_Error( cv::Error::StsError, "samples is empty" );
filteredSamples.clear();
@ -1121,7 +1120,7 @@ void CirclesGridFinder::filterOutliersByDensity(const std::vector<Point2f> &samp
}
if (filteredSamples.empty())
CV_Error( 0, "filteredSamples is empty" );
CV_Error( cv::Error::StsError, "filteredSamples is empty" );
}
void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vector<Point2f> &basis, std::vector<Graph> &basisGraphs)
@ -1149,7 +1148,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
}
}
if (basis.size() != 2)
CV_Error(0, "Basis size is not 2");
CV_Error(cv::Error::StsError, "Basis size is not 2");
if (basis[1].x > basis[0].x)
{
@ -1159,7 +1158,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
const float minBasisDif = 2;
if (norm(basis[0] - basis[1]) < minBasisDif)
CV_Error(0, "degenerate basis" );
CV_Error(cv::Error::StsError, "degenerate basis" );
std::vector<std::vector<Point2f> > clusters(2), hulls(2);
for (int k = 0; k < (int)samples.size(); k++)
@ -1200,7 +1199,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
}
}
if (basisGraphs.size() != 2)
CV_Error(0, "Number of basis graphs is not 2");
CV_Error(cv::Error::StsError, "Number of basis graphs is not 2");
}
void CirclesGridFinder::computeRNG(Graph &rng, std::vector<cv::Point2f> &vectors, Mat *drawImage) const
@ -1326,8 +1325,6 @@ size_t CirclesGridFinder::findLongestPath(std::vector<Graph> &basisGraphs, Path
confidences.push_back(conf);
}
}
//if( bestGraphIdx != 0 )
//CV_Error( 0, "" );
int maxConf = -1;
int bestPathIdx = -1;

@ -101,55 +101,9 @@
namespace cv {
//! @addtogroup core_utils
//! @addtogroup core
//! @{
/*! @brief Class passed to an error.
This class encapsulates all or almost all necessary
information about the error happened in the program. The exception is
usually constructed and thrown implicitly via CV_Error and CV_Error_ macros.
@see error
*/
class CV_EXPORTS Exception : public std::exception
{
public:
/*!
Default constructor
*/
Exception();
/*!
Full constructor. Normally the constructor is not called explicitly.
Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
*/
Exception(int _code, const String& _err, const String& _func, const String& _file, int _line);
virtual ~Exception() CV_NOEXCEPT;
/*!
\return the error description and the context as a text string.
*/
virtual const char *what() const CV_NOEXCEPT CV_OVERRIDE;
void formatMessage();
String msg; ///< the formatted error message
int code; ///< error code @see CVStatus
String err; ///< error description
String func; ///< function name. Available only when the compiler supports getting it
String file; ///< source file name where the error has occurred
int line; ///< line number in the source file where the error has occurred
};
/*! @brief Signals an error and raises the exception.
By default the function prints information about the error to stderr,
then it either stops if cv::setBreakOnError() had been called before or raises the exception.
It is possible to alternate error processing by using #redirectError().
@param exc the exception raisen.
@deprecated drop this version
*/
CV_EXPORTS CV_NORETURN void error(const Exception& exc);
enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently
SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted
//!< independently; this flag and the previous one are
@ -161,11 +115,6 @@ enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independe
//!< mutually exclusive.
};
//! @} core_utils
//! @addtogroup core
//! @{
//! Covariation flags
enum CovarFlags {
/** The output covariance matrix is calculated as:

@ -60,72 +60,6 @@
namespace cv
{
//! @addtogroup core_utils
//! @{
namespace Error {
//! error codes
enum Code {
StsOk= 0, //!< everything is ok
StsBackTrace= -1, //!< pseudo error for back trace
StsError= -2, //!< unknown /unspecified error
StsInternal= -3, //!< internal error (bad state)
StsNoMem= -4, //!< insufficient memory
StsBadArg= -5, //!< function arg/param is bad
StsBadFunc= -6, //!< unsupported function
StsNoConv= -7, //!< iteration didn't converge
StsAutoTrace= -8, //!< tracing
HeaderIsNull= -9, //!< image header is NULL
BadImageSize= -10, //!< image size is invalid
BadOffset= -11, //!< offset is invalid
BadDataPtr= -12, //!<
BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix.
BadModelOrChSeq= -14, //!<
BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices.
BadNumChannel1U= -16, //!<
BadDepth= -17, //!< input image depth is not supported by the function
BadAlphaChannel= -18, //!<
BadOrder= -19, //!< number of dimensions is out of range
BadOrigin= -20, //!< incorrect input origin
BadAlign= -21, //!< incorrect input align
BadCallBack= -22, //!<
BadTileSize= -23, //!<
BadCOI= -24, //!< input COI is not supported
BadROISize= -25, //!< incorrect input roi
MaskIsTiled= -26, //!<
StsNullPtr= -27, //!< null pointer
StsVecLengthErr= -28, //!< incorrect vector length
StsFilterStructContentErr= -29, //!< incorrect filter structure content
StsKernelStructContentErr= -30, //!< incorrect transform kernel content
StsFilterOffsetErr= -31, //!< incorrect filter offset value
StsBadSize= -201, //!< the input/output structure size is incorrect
StsDivByZero= -202, //!< division by zero
StsInplaceNotSupported= -203, //!< in-place operation is not supported
StsObjectNotFound= -204, //!< request can't be completed
StsUnmatchedFormats= -205, //!< formats of input/output arrays differ
StsBadFlag= -206, //!< flag is wrong or not supported
StsBadPoint= -207, //!< bad CvPoint
StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match
StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function
StsOutOfRange= -211, //!< some of parameters are out of range
StsParseError= -212, //!< invalid syntax/structure of the parsed file
StsNotImplemented= -213, //!< the requested function/feature is not implemented
StsBadMemBlock= -214, //!< an allocated block has been corrupted
StsAssert= -215, //!< assertion failed
GpuNotSupported= -216, //!< no CUDA support
GpuApiCallError= -217, //!< GPU API call error
OpenGlNotSupported= -218, //!< no OpenGL support
OpenGlApiCallError= -219, //!< OpenGL API call error
OpenCLApiCallError= -220, //!< OpenCL API call error
OpenCLDoubleNotSupported= -221,
OpenCLInitError= -222, //!< OpenCL initialization error
OpenCLNoAMDBlasFft= -223
};
} //Error
//! @} core_utils
//! @addtogroup core_array
//! @{
@ -280,119 +214,10 @@ enum BorderTypes {
//! @} core_array
//! @addtogroup core_utils
//! @{
/*! @brief Signals an error and raises the exception.
By default the function prints information about the error to stderr,
then it either stops if setBreakOnError() had been called before or raises the exception.
It is possible to alternate error processing by using redirectError().
@param _code - error code (Error::Code)
@param _err - error description
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert
*/
CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
/*! @brief Signals an error and terminate application.
By default the function prints information about the error to stderr, then it terminates application
with std::terminate. The function is designed for invariants check in functions and methods with
noexcept attribute.
@param _code - error code (Error::Code)
@param _err - error description
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_AssertTerminate
*/
CV_EXPORTS CV_NORETURN void terminate(int _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT;
#ifdef CV_STATIC_ANALYSIS
// In practice, some macro are not processed correctly (noreturn is not detected).
// We need to use simplified definition for them.
#define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0)
#define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0)
#define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0)
#else // CV_STATIC_ANALYSIS
/** @brief Call the error handler.
Currently, the error handler prints the error code and the error message to the standard
error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
the execution stack and all the parameters can be analyzed by the debugger. In the Release
configuration, the exception is thrown.
@param code one of Error::Code
@param msg error message
*/
#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
/** @brief Call the error handler.
This macro can be used to construct an error message on-fly to include some dynamic information,
for example:
@code
// note the extra parentheses around the formatted text message
CV_Error_(Error::StsOutOfRange,
("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
@endcode
@param code one of Error::Code
@param args printf-like formatted error message in parentheses
*/
#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
/** @brief Checks a condition at runtime and throws exception if it fails
The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
configurations while CV_DbgAssert is only retained in the Debug configuration.
CV_AssertTerminate is analog of CV_Assert for invariants check in functions with noexcept attribute.
It does not throw exception, but terminates the application.
*/
#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#define CV_AssertTerminate( expr ) do { if(!!(expr)) ; else cv::terminate( #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#endif // CV_STATIC_ANALYSIS
//! @cond IGNORED
#if !defined(__OPENCV_BUILD) // TODO: backward compatibility only
#ifndef CV_ErrorNoReturn
#define CV_ErrorNoReturn CV_Error
#endif
#ifndef CV_ErrorNoReturn_
#define CV_ErrorNoReturn_ CV_Error_
#endif
#endif
#define CV_Assert_1 CV_Assert
#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ ))
#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ ))
#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ ))
#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ ))
#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ ))
#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ ))
#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ ))
#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ ))
#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ ))
#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0)
//! @endcond
#if defined _DEBUG || defined CV_STATIC_ANALYSIS
# define CV_DbgAssert(expr) CV_Assert(expr)
#else
/** replaced with CV_Assert(expr) in Debug configuration */
# define CV_DbgAssert(expr)
#endif
/*
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
* bit count of A exclusive XOR'ed with B
@ -531,65 +356,10 @@ CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep,
/** proxy for hal::Cholesky */
CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
////////////////// forward declarations for important OpenCV types //////////////////
//! @cond IGNORED
template<typename _Tp, int cn> class Vec;
template<typename _Tp, int m, int n> class Matx;
template<typename _Tp> class Complex;
template<typename _Tp> class Point_;
template<typename _Tp> class Point3_;
template<typename _Tp> class Size_;
template<typename _Tp> class Rect_;
template<typename _Tp> class Scalar_;
class CV_EXPORTS RotatedRect;
class CV_EXPORTS Range;
class CV_EXPORTS TermCriteria;
class CV_EXPORTS KeyPoint;
class CV_EXPORTS DMatch;
class CV_EXPORTS RNG;
class CV_EXPORTS Mat;
class CV_EXPORTS MatExpr;
class CV_EXPORTS UMat;
class CV_EXPORTS SparseMat;
typedef Mat MatND;
template<typename _Tp> class Mat_;
template<typename _Tp> class SparseMat_;
class CV_EXPORTS MatConstIterator;
class CV_EXPORTS SparseMatIterator;
class CV_EXPORTS SparseMatConstIterator;
template<typename _Tp> class MatIterator_;
template<typename _Tp> class MatConstIterator_;
template<typename _Tp> class SparseMatIterator_;
template<typename _Tp> class SparseMatConstIterator_;
//! @} core_utils
namespace ogl
{
class CV_EXPORTS Buffer;
class CV_EXPORTS Texture2D;
class CV_EXPORTS Arrays;
}
namespace cuda
{
class CV_EXPORTS GpuMat;
class CV_EXPORTS HostMem;
class CV_EXPORTS Stream;
class CV_EXPORTS Event;
}
namespace cudev
{
template <typename _Tp> class GpuMat_;
}
//! @cond IGNORED
namespace ipp
{
@ -615,15 +385,12 @@ static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); }
//! @endcond
//! @} core_utils
} // cv
#include "opencv2/core/fwddecl.hpp"
#include "opencv2/core/neon_utils.hpp"
#include "opencv2/core/vsx_utils.hpp"
#include "opencv2/core/exception.hpp"
#include "opencv2/core/check.hpp"
#endif //OPENCV_CORE_BASE_HPP

@ -5,7 +5,9 @@
#ifndef OPENCV_CORE_CHECK_HPP
#define OPENCV_CORE_CHECK_HPP
#include <opencv2/core/base.hpp>
#include "opencv2/core/cvdef.h"
#include "opencv2/core/cvstd.hpp"
#include "opencv2/core/fwddecl.hpp"
namespace cv {

@ -1073,7 +1073,7 @@ CVAPI(void) cvExp( const CvArr* src, CvArr* dst );
/** Checks array values for NaNs, Infs or simply for too large numbers
(if CV_CHECK_RANGE is set). If CV_CHECK_QUIET is set,
no runtime errors is raised (function returns zero value in case of "bad" values).
Otherwise cvError is called */
*/
CVAPI(int) cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0),
double min_val CV_DEFAULT(0), double max_val CV_DEFAULT(0));
#define cvCheckArray cvCheckArr
@ -1809,14 +1809,6 @@ CVAPI(int) cvGetErrMode( void );
/** Sets error processing mode, returns previously used mode */
CVAPI(int) cvSetErrMode( int mode );
/** Sets error status and performs some additional actions (displaying message box,
writing message to stderr, terminating application etc.)
depending on the current error mode */
CVAPI(void) cvError( int status, const char* func_name,
const char* err_msg, const char* file_name, int line );
/** Retrieves textual description of the error given its code */
CVAPI(const char*) cvErrorStr( int status );
/** Retrieves detailed information about the last error occurred */
CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description,
@ -1827,7 +1819,7 @@ CVAPI(int) cvErrorFromIppStatus( int ipp_status );
#define OPENCV_ERROR(status,func,context) \
cvError((status),(func),(context),__FILE__,__LINE__)
cv::error((status),(func),(context),__FILE__,__LINE__)
#define OPENCV_ASSERT(expr,func,context) \
{if (! (expr)) \
@ -1855,7 +1847,7 @@ static char cvFuncName[] = Name
*/
#define CV_ERROR( Code, Msg ) \
{ \
cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \
cv::error( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \
__CV_EXIT__; \
}

@ -0,0 +1,239 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CORE_EXCEPTION_HPP
#define OPENCV_CORE_EXCEPTION_HPP
#include "opencv2/core/cvdef.h"
#include "opencv2/core/cvstd.hpp"
namespace cv {
//! @addtogroup core_utils
//! @{
namespace Error {
//! error codes
enum Code {
StsOk= 0, //!< everything is ok
StsBackTrace= -1, //!< pseudo error for back trace
StsError= -2, //!< unknown /unspecified error
StsInternal= -3, //!< internal error (bad state)
StsNoMem= -4, //!< insufficient memory
StsBadArg= -5, //!< function arg/param is bad
StsBadFunc= -6, //!< unsupported function
StsNoConv= -7, //!< iteration didn't converge
StsAutoTrace= -8, //!< tracing
HeaderIsNull= -9, //!< image header is NULL
BadImageSize= -10, //!< image size is invalid
BadOffset= -11, //!< offset is invalid
BadDataPtr= -12, //!<
BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix.
BadModelOrChSeq= -14, //!<
BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices.
BadNumChannel1U= -16, //!<
BadDepth= -17, //!< input image depth is not supported by the function
BadAlphaChannel= -18, //!<
BadOrder= -19, //!< number of dimensions is out of range
BadOrigin= -20, //!< incorrect input origin
BadAlign= -21, //!< incorrect input align
BadCallBack= -22, //!<
BadTileSize= -23, //!<
BadCOI= -24, //!< input COI is not supported
BadROISize= -25, //!< incorrect input roi
MaskIsTiled= -26, //!<
StsNullPtr= -27, //!< null pointer
StsVecLengthErr= -28, //!< incorrect vector length
StsFilterStructContentErr= -29, //!< incorrect filter structure content
StsKernelStructContentErr= -30, //!< incorrect transform kernel content
StsFilterOffsetErr= -31, //!< incorrect filter offset value
StsBadSize= -201, //!< the input/output structure size is incorrect
StsDivByZero= -202, //!< division by zero
StsInplaceNotSupported= -203, //!< in-place operation is not supported
StsObjectNotFound= -204, //!< request can't be completed
StsUnmatchedFormats= -205, //!< formats of input/output arrays differ
StsBadFlag= -206, //!< flag is wrong or not supported
StsBadPoint= -207, //!< bad CvPoint
StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match
StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function
StsOutOfRange= -211, //!< some of parameters are out of range
StsParseError= -212, //!< invalid syntax/structure of the parsed file
StsNotImplemented= -213, //!< the requested function/feature is not implemented
StsBadMemBlock= -214, //!< an allocated block has been corrupted
StsAssert= -215, //!< assertion failed
GpuNotSupported= -216, //!< no CUDA support
GpuApiCallError= -217, //!< GPU API call error
OpenGlNotSupported= -218, //!< no OpenGL support
OpenGlApiCallError= -219, //!< OpenGL API call error
OpenCLApiCallError= -220, //!< OpenCL API call error
OpenCLDoubleNotSupported= -221,
OpenCLInitError= -222, //!< OpenCL initialization error
OpenCLNoAMDBlasFft= -223
};
} // Error::
/*! @brief Class passed to an error.
This class encapsulates all or almost all necessary
information about the error happened in the program. The exception is
usually constructed and thrown implicitly via CV_Error and CV_Error_ macros.
@see error
*/
class CV_EXPORTS Exception : public std::exception
{
public:
/*!
Default constructor
*/
Exception();
/*!
Full constructor. Normally the constructor is not called explicitly.
Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used.
*/
Exception(Error::Code _code, const std::string& _err, const std::string& _func, const std::string& _file, int _line);
virtual ~Exception() CV_NOEXCEPT;
/*!
\return the error description and the context as a text string.
*/
virtual const char *what() const CV_NOEXCEPT CV_OVERRIDE;
void formatMessage();
const char * codeMessage() const;
std::string msg; ///< the formatted error message
Error::Code code; ///< error code @see CVStatus
std::string err; ///< error description
std::string func; ///< function name. Available only when the compiler supports getting it
std::string file; ///< source file name where the error has occurred
int line; ///< line number in the source file where the error has occurred
};
/*! @brief Signals an error and raises the exception.
By default the function prints information about the error to stderr,
then it either stops if cv::setBreakOnError() had been called before or raises the exception.
It is possible to alternate error processing by using #redirectError().
@param exc the exception raisen.
@deprecated drop this version
*/
CV_EXPORTS CV_NORETURN void error(const Exception& exc);
/*! @brief Signals an error and raises the exception.
By default the function prints information about the error to stderr,
then it either stops if setBreakOnError() had been called before or raises the exception.
It is possible to alternate error processing by using redirectError().
@param _code - error code (Error::Code)
@param _err - error description
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert
*/
CV_EXPORTS CV_NORETURN void error(Error::Code _code, const String& _err, const char* _func, const char* _file, int _line);
/*! @brief Signals an error and terminate application.
By default the function prints information about the error to stderr, then it terminates application
with std::terminate. The function is designed for invariants check in functions and methods with
noexcept attribute.
@param _code - error code (Error::Code)
@param _err - error description
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_AssertTerminate
*/
CV_EXPORTS CV_NORETURN void terminate(Error::Code _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT;
#ifdef CV_STATIC_ANALYSIS
// In practice, some macro are not processed correctly (noreturn is not detected).
// We need to use simplified definition for them.
#define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0)
#define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0)
#define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0)
#else // CV_STATIC_ANALYSIS
/** @brief Call the error handler.
Currently, the error handler prints the error code and the error message to the standard
error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
the execution stack and all the parameters can be analyzed by the debugger. In the Release
configuration, the exception is thrown.
@param code one of Error::Code
@param msg error message
*/
#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
/** @brief Call the error handler.
This macro can be used to construct an error message on-fly to include some dynamic information,
for example:
@code
// note the extra parentheses around the formatted text message
CV_Error_(Error::StsOutOfRange,
("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
@endcode
@param code one of Error::Code
@param args printf-like formatted error message in parentheses
*/
#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
/** @brief Checks a condition at runtime and throws exception if it fails
The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
configurations while CV_DbgAssert is only retained in the Debug configuration.
CV_AssertTerminate is analog of CV_Assert for invariants check in functions with noexcept attribute.
It does not throw exception, but terminates the application.
*/
#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#define CV_AssertTerminate( expr ) do { if(!!(expr)) ; else cv::terminate( #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#endif // CV_STATIC_ANALYSIS
//! @cond IGNORED
#if !defined(__OPENCV_BUILD) // TODO: backward compatibility only
#ifndef CV_ErrorNoReturn
#define CV_ErrorNoReturn CV_Error
#endif
#ifndef CV_ErrorNoReturn_
#define CV_ErrorNoReturn_ CV_Error_
#endif
#endif
#define CV_Assert_1 CV_Assert
#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ ))
#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ ))
#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ ))
#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ ))
#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ ))
#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ ))
#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ ))
#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ ))
#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ ))
#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0)
//! @endcond
#if defined _DEBUG || defined CV_STATIC_ANALYSIS
# define CV_DbgAssert(expr) CV_Assert(expr)
#else
/** replaced with CV_Assert(expr) in Debug configuration */
# define CV_DbgAssert(expr)
#endif
//! @} core_utils
} // cv::
#endif // OPENCV_CORE_EXCEPTION_HPP

@ -0,0 +1,76 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CORE_FWDDECL_HPP
#define OPENCV_CORE_FWDDECL_HPP
#include "opencv2/core/cvdef.h"
namespace cv {
//! @cond IGNORED
////////////////// forward declarations for important OpenCV types //////////////////
template<typename _Tp, int cn> class Vec;
template<typename _Tp, int m, int n> class Matx;
template<typename _Tp> class Complex;
template<typename _Tp> class Point_;
template<typename _Tp> class Point3_;
template<typename _Tp> class Size_;
template<typename _Tp> class Rect_;
template<typename _Tp> class Scalar_;
class CV_EXPORTS RotatedRect;
class CV_EXPORTS Range;
class CV_EXPORTS TermCriteria;
class CV_EXPORTS KeyPoint;
class CV_EXPORTS DMatch;
class CV_EXPORTS RNG;
class CV_EXPORTS Mat;
class CV_EXPORTS MatExpr;
class CV_EXPORTS UMat;
class CV_EXPORTS SparseMat;
typedef Mat MatND;
template<typename _Tp> class Mat_;
template<typename _Tp> class SparseMat_;
class CV_EXPORTS MatConstIterator;
class CV_EXPORTS SparseMatIterator;
class CV_EXPORTS SparseMatConstIterator;
template<typename _Tp> class MatIterator_;
template<typename _Tp> class MatConstIterator_;
template<typename _Tp> class SparseMatIterator_;
template<typename _Tp> class SparseMatConstIterator_;
namespace ogl
{
class CV_EXPORTS Buffer;
class CV_EXPORTS Texture2D;
class CV_EXPORTS Arrays;
}
namespace cuda
{
class CV_EXPORTS GpuMat;
class CV_EXPORTS HostMem;
class CV_EXPORTS Stream;
class CV_EXPORTS Event;
}
namespace cudev
{
template <typename _Tp> class GpuMat_;
}
//! @endcond
} // cv::
#endif // OPENCV_CORE_FWDDECL_HPP

@ -8,7 +8,7 @@
#ifndef OPENCV_HAL_INTRIN_RVV_SCALABLE_HPP
#define OPENCV_HAL_INTRIN_RVV_SCALABLE_HPP
#include <opencv2/core/check.hpp>
#include <opencv2/core/base.hpp>
#if defined(__GNUC__) && !defined(__clang__)
// FIXIT: eliminate massive warnigs from templates

@ -189,7 +189,7 @@ CV_IMPL void
cvReleaseMat( CvMat** array )
{
if( !array )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
if( *array )
{
@ -393,7 +393,7 @@ CV_IMPL void
cvReleaseSparseMat( CvSparseMat** array )
{
if( !array )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
if( *array )
{
@ -2464,7 +2464,7 @@ cvInitImageHeader( IplImage * image, CvSize size, int depth,
const char *colorModel, *channelSeq;
if( !image )
CV_Error( CV_HeaderIsNull, "null pointer to header" );
CV_Error( cv::Error::HeaderIsNull, "null pointer to header" );
*image = cvIplImage();
@ -2568,7 +2568,7 @@ CV_IMPL void
cvSetImageROI( IplImage* image, CvRect rect )
{
if( !image )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
// allow zero ROI width or height
CV_Assert( rect.width >= 0 && rect.height >= 0 &&
@ -2603,7 +2603,7 @@ CV_IMPL void
cvResetImageROI( IplImage* image )
{
if( !image )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
if( image->roi )
{
@ -2641,7 +2641,7 @@ CV_IMPL void
cvSetImageCOI( IplImage* image, int coi )
{
if( !image )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
if( (unsigned)coi > (unsigned)(image->nChannels) )
CV_Error( cv::Error::BadCOI, "" );
@ -2664,7 +2664,7 @@ CV_IMPL int
cvGetImageCOI( const IplImage* image )
{
if( !image )
CV_Error( CV_HeaderIsNull, "" );
CV_Error( cv::Error::HeaderIsNull, "" );
return image->roi ? image->roi->coi : 0;
}

@ -319,9 +319,9 @@ DECLARE_CV_CPUID_X86
namespace cv
{
Exception::Exception() { code = 0; line = 0; }
Exception::Exception() { code = Error::StsOk; line = 0; }
Exception::Exception(int _code, const String& _err, const String& _func, const String& _file, int _line)
Exception::Exception(Error::Code _code, const String& _err, const String& _func, const String& _file, int _line)
: code(_code), err(_err), func(_func), file(_file), line(_line)
{
formatMessage();
@ -356,16 +356,66 @@ void Exception::formatMessage()
if (func.size() > 0)
{
if (multiline)
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) in function '%s'\n%s", CV_VERSION, file.c_str(), line, code, cvErrorStr(code), func.c_str(), err.c_str());
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) in function '%s'\n%s", CV_VERSION, file.c_str(), line, code, codeMessage(), func.c_str(), err.c_str());
else
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) %s in function '%s'\n", CV_VERSION, file.c_str(), line, code, cvErrorStr(code), err.c_str(), func.c_str());
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) %s in function '%s'\n", CV_VERSION, file.c_str(), line, code, codeMessage(), err.c_str(), func.c_str());
}
else
{
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) %s%s", CV_VERSION, file.c_str(), line, code, cvErrorStr(code), err.c_str(), multiline ? "" : "\n");
msg = format("OpenCV(%s) %s:%d: error: (%d:%s) %s%s", CV_VERSION, file.c_str(), line, code, codeMessage(), err.c_str(), multiline ? "" : "\n");
}
}
const char * Exception::codeMessage() const
{
switch (code)
{
case cv::Error::StsOk : return "No Error";
case cv::Error::StsBackTrace : return "Backtrace";
case cv::Error::StsError : return "Unspecified error";
case cv::Error::StsInternal : return "Internal error";
case cv::Error::StsNoMem : return "Insufficient memory";
case cv::Error::StsBadArg : return "Bad argument";
case cv::Error::StsNoConv : return "Iterations do not converge";
case cv::Error::StsAutoTrace : return "Autotrace call";
case cv::Error::StsBadSize : return "Incorrect size of input array";
case cv::Error::StsNullPtr : return "Null pointer";
case cv::Error::StsDivByZero : return "Division by zero occurred";
case cv::Error::BadStep : return "Image step is wrong";
case cv::Error::StsInplaceNotSupported : return "Inplace operation is not supported";
case cv::Error::StsObjectNotFound : return "Requested object was not found";
case cv::Error::BadDepth : return "Input image depth is not supported by function";
case cv::Error::StsUnmatchedFormats : return "Formats of input arguments do not match";
case cv::Error::StsUnmatchedSizes : return "Sizes of input arguments do not match";
case cv::Error::StsOutOfRange : return "One of the arguments\' values is out of range";
case cv::Error::StsUnsupportedFormat : return "Unsupported format or combination of formats";
case cv::Error::BadCOI : return "Input COI is not supported";
case cv::Error::BadNumChannels : return "Bad number of channels";
case cv::Error::StsBadFlag : return "Bad flag (parameter or structure field)";
case cv::Error::StsBadPoint : return "Bad parameter of type CvPoint";
case cv::Error::StsBadMask : return "Bad type of mask argument";
case cv::Error::StsParseError : return "Parsing error";
case cv::Error::StsNotImplemented : return "The function/feature is not implemented";
case cv::Error::StsBadMemBlock : return "Memory block has been corrupted";
case cv::Error::StsAssert : return "Assertion failed";
case cv::Error::GpuNotSupported : return "No CUDA support";
case cv::Error::GpuApiCallError : return "Gpu API call";
case cv::Error::OpenGlNotSupported : return "No OpenGL support";
case cv::Error::OpenGlApiCallError : return "OpenGL API call";
case cv::Error::OpenCLApiCallError : return "OpenCL API call error";
case cv::Error::OpenCLDoubleNotSupported:return "OpenCL device does not support double";
case cv::Error::OpenCLInitError : return "OpenCL initialization error";
case cv::Error::OpenCLNoAMDBlasFft : return "Missing OpenCL AMD BLAS FFT";
default:
{
static char buf[256] {0};
snprintf(buf, sizeof(buf), "Unknown %s code %d", code >= 0 ? "status":"error", code);
return buf;
}
};
}
static const char* g_hwFeatureNames[CV_HARDWARE_MAX_FEATURE] = { NULL };
static const char* getHWFeatureName(int id)
@ -1221,7 +1271,7 @@ int cv_vsnprintf(char* buf, int len, const char* fmt, va_list args)
static void dumpException(const Exception& exc)
{
const char* errorStr = cvErrorStr(exc.code);
const char* errorStr = exc.codeMessage();
char buf[1 << 12];
cv_snprintf(buf, sizeof(buf),
@ -1299,7 +1349,7 @@ void error( const Exception& exc )
#endif
}
void error(int _code, const String& _err, const char* _func, const char* _file, int _line)
void error(Error::Code _code, const String& _err, const char* _func, const char* _file, int _line)
{
error(cv::Exception(_code, _err, _func, _file, _line));
#ifdef __GNUC__
@ -1332,7 +1382,7 @@ redirectError( ErrorCallback errCallback, void* userdata, void** prevUserdata)
return prevCallback;
}
void terminate(int _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT
void terminate(Error::Code _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT
{
dumpException(cv::Exception(_code, _err, _func, _file, _line));
std::terminate();
@ -1340,55 +1390,6 @@ void terminate(int _code, const String& _err, const char* _func, const char* _fi
}
CV_IMPL const char* cvErrorStr( int status )
{
static char buf[256];
switch (status)
{
case cv::Error::StsOk : return "No Error";
case cv::Error::StsBackTrace : return "Backtrace";
case cv::Error::StsError : return "Unspecified error";
case cv::Error::StsInternal : return "Internal error";
case cv::Error::StsNoMem : return "Insufficient memory";
case cv::Error::StsBadArg : return "Bad argument";
case cv::Error::StsNoConv : return "Iterations do not converge";
case cv::Error::StsAutoTrace : return "Autotrace call";
case cv::Error::StsBadSize : return "Incorrect size of input array";
case cv::Error::StsNullPtr : return "Null pointer";
case cv::Error::StsDivByZero : return "Division by zero occurred";
case cv::Error::BadStep : return "Image step is wrong";
case cv::Error::StsInplaceNotSupported : return "Inplace operation is not supported";
case cv::Error::StsObjectNotFound : return "Requested object was not found";
case cv::Error::BadDepth : return "Input image depth is not supported by function";
case cv::Error::StsUnmatchedFormats : return "Formats of input arguments do not match";
case cv::Error::StsUnmatchedSizes : return "Sizes of input arguments do not match";
case cv::Error::StsOutOfRange : return "One of the arguments\' values is out of range";
case cv::Error::StsUnsupportedFormat : return "Unsupported format or combination of formats";
case cv::Error::BadCOI : return "Input COI is not supported";
case cv::Error::BadNumChannels : return "Bad number of channels";
case cv::Error::StsBadFlag : return "Bad flag (parameter or structure field)";
case cv::Error::StsBadPoint : return "Bad parameter of type CvPoint";
case cv::Error::StsBadMask : return "Bad type of mask argument";
case cv::Error::StsParseError : return "Parsing error";
case cv::Error::StsNotImplemented : return "The function/feature is not implemented";
case cv::Error::StsBadMemBlock : return "Memory block has been corrupted";
case cv::Error::StsAssert : return "Assertion failed";
case cv::Error::GpuNotSupported : return "No CUDA support";
case cv::Error::GpuApiCallError : return "Gpu API call";
case cv::Error::OpenGlNotSupported : return "No OpenGL support";
case cv::Error::OpenGlApiCallError : return "OpenGL API call";
case cv::Error::OpenCLApiCallError : return "OpenCL API call error";
case cv::Error::OpenCLDoubleNotSupported:return "OpenCL device does not support double";
case cv::Error::OpenCLInitError : return "OpenCL initialization error";
case cv::Error::OpenCLNoAMDBlasFft : return "Missing OpenCL AMD BLAS FFT";
};
snprintf(buf, sizeof(buf), "Unknown %s code %d", status >= 0 ? "status":"error", status);
return buf;
}
CV_IMPL int cvGetErrMode(void)
{
return 0;
@ -1408,14 +1409,6 @@ CV_IMPL void cvSetErrStatus(int)
{
}
CV_IMPL void cvError( int code, const char* func_name,
const char* err_msg,
const char* file_name, int line )
{
cv::error(cv::Exception(code, err_msg, func_name, file_name, line));
}
/* function, which converts int to int */
CV_IMPL int
cvErrorFromIppStatus( int status )

@ -44,8 +44,6 @@
namespace opencv_test { namespace {
#define CORE_COUNTNONZERO_ERROR_COUNT 1
#define MESSAGE_ERROR_COUNT "Count non zero elements returned by OpenCV function is incorrect."
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
@ -203,7 +201,7 @@ void CV_CountNonZeroTest::run(int)
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: RANDOM" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_COUNT);
return;
}
@ -219,7 +217,7 @@ void CV_CountNonZeroTest::run(int)
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: HALF-RANDOM" << endl;
print_information(count_non_zero, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_COUNT);
return;
}
@ -235,7 +233,7 @@ void CV_CountNonZeroTest::run(int)
cout << "Number of experiment: " << i << endl;
cout << "Method of data generation: STATISTIC" << endl;
print_information(right, result);
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_COUNT);
return;
}

@ -45,12 +45,6 @@ namespace opencv_test { namespace {
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1
#define CORE_EIGEN_ERROR_COUNT 1
#define CORE_EIGEN_ERROR_SIZE 2
#define CORE_EIGEN_ERROR_DIFF 3
#define CORE_EIGEN_ERROR_ORTHO 4
#define CORE_EIGEN_ERROR_ORDER 5
#define MESSAGE_ERROR_COUNT "Matrix of eigen values must have the same rows as source matrix and 1 column."
#define MESSAGE_ERROR_SIZE "Source matrix and matrix of eigen vectors must have the same sizes."
#define MESSAGE_ERROR_DIFF_1 "Accuracy of eigen values computing less than required."
@ -173,7 +167,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std::cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_COUNT);
}
return true;
}
@ -188,7 +182,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues
std::cout << endl; std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl;
std::cout << "Number of rows: " << evectors.rows << " Number of cols: " << evectors.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_SIZE, MESSAGE_ERROR_SIZE);
CV_Error (cv::Error::StsError, MESSAGE_ERROR_SIZE);
}
if (!(evalues.rows == right_eigen_pair_count && evalues.cols == 1))
@ -196,7 +190,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues
std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl;
std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl;
std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl;
CV_Error (CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT);
CV_Error (cv::Error::StsError, MESSAGE_ERROR_COUNT);
}
return true;
@ -233,7 +227,7 @@ bool Core_EigenTest::check_orthogonality(const cv::Mat& U)
{
std::cout << endl; std::cout << "Checking orthogonality of matrix " << U << ": ";
print_information(i, U, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_ORTHO, MESSAGE_ERROR_ORTHO);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_ORTHO);
}
}
@ -252,7 +246,7 @@ bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values)
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non descending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, MESSAGE_ERROR_ORDER);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_ORDER);
}
break;
@ -266,7 +260,7 @@ bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values)
std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl;
std::cout << "Pair of indexes with non descending of eigen values: (" << i << ", " << i+1 << ")." << endl;
std::cout << endl;
CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in descending order.");
CV_Error(cv::Error::StsError, "Eigen values are not sorted in descending order.");
}
break;
@ -324,7 +318,7 @@ bool Core_EigenTest::test_pairs(const cv::Mat& src)
{
std::cout << endl; std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": ";
print_information(i, src, diff, eps_vec);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_2);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_DIFF_2);
}
}
@ -352,7 +346,7 @@ bool Core_EigenTest::test_values(const cv::Mat& src)
{
std::cout << endl; std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": ";
print_information(i, src, diff, eps_val);
CV_Error(CORE_EIGEN_ERROR_DIFF, MESSAGE_ERROR_DIFF_1);
CV_Error(cv::Error::StsError, MESSAGE_ERROR_DIFF_1);
}
}

@ -34,17 +34,7 @@
#include <opencv2\highgui\highgui_winrt.hpp>
#include "window_winrt_bridge.hpp"
#define CV_WINRT_NO_GUI_ERROR( funcname ) \
{ \
cvError( cv::Error::StsNotImplemented, funcname, \
"The function is not implemented. ", \
__FILE__, __LINE__ ); \
}
#define CV_Error( Code, Msg ) \
{ \
cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \
};
#define CV_WINRT_NO_GUI_ERROR( funcname ) CV_Error(cv::Error::StsNotImplemented, "The function is not implemented")
/********************************** WinRT Specific API Implementation ******************************************/

@ -52,7 +52,7 @@ namespace cv
class RBS_ ## name ## _Exception : public cv::Exception \
{ \
public: \
RBS_ ## name ## _Exception(int code_, const String& err_, const String& func_, const String& file_, int line_) : \
RBS_ ## name ## _Exception(cv::Error::Code code_, const String& err_, const String& func_, const String& file_, int line_) : \
cv::Exception(code_, err_, func_, file_, line_) \
{} \
};

@ -9,8 +9,6 @@
#include "opencv2/core/utils/logger.hpp"
#include "pyopencv_generated_include.h"
#include "opencv2/core/types_c.h"
#include "cv2_util.hpp"
#include "cv2_numpy.hpp"

@ -185,7 +185,7 @@ DpSeamFinder::DpSeamFinder(String costFunc)
else if (costFunc == "COLOR_GRAD")
costFunc_ = COLOR_GRAD;
else
CV_Error(-1, "Unknown cost function");
CV_Error(cv::Error::StsError, "Unknown cost function");
}
void DpSeamFinder::setCostFunction(String costFunc)
@ -195,7 +195,7 @@ void DpSeamFinder::setCostFunction(String costFunc)
else if (costFunc == "COLOR_GRAD")
costFunc_ = COLOR_GRAD;
else
CV_Error(-1, "Unknown cost function");
CV_Error(cv::Error::StsError, "Unknown cost function");
}
void DpSeamFinder::find(const std::vector<UMat> &src, const std::vector<Point> &corners, std::vector<UMat> &masks)

@ -42,8 +42,6 @@
#include "precomp.hpp"
#include <opencv2/core/utils/configuration.private.hpp>
#include "opencv2/core/core_c.h"
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
@ -308,7 +306,7 @@ void BaseTest::safe_run( int start_from )
}
catch (const cv::Exception& exc)
{
const char* errorStr = cvErrorStr(exc.code);
const char* errorStr = exc.codeMessage();
char buf[1 << 16];
const char* delim = exc.err.find('\n') == cv::String::npos ? "" : "\n";
@ -522,7 +520,7 @@ string TS::str_from_code( const TS::FailureCode code )
case FAIL_GENERIC: return "Generic/Unknown";
case FAIL_MISSING_TEST_DATA: return "No test data";
case FAIL_INVALID_TEST_DATA: return "Invalid test data";
case FAIL_ERROR_IN_CALLED_FUNC: return "cvError invoked";
case FAIL_ERROR_IN_CALLED_FUNC: return "Error invoked";
case FAIL_EXCEPTION: return "Hardware/OS exception";
case FAIL_MEMORY_EXCEPTION: return "Invalid memory access";
case FAIL_ARITHM_EXCEPTION: return "Arithmetic exception";
@ -544,7 +542,7 @@ static int tsErrorCallback( int status, const char* func_name, const char* err_m
{
TS* ts = (TS*)data;
const char* delim = std::string(err_msg).find('\n') == std::string::npos ? "" : "\n";
ts->printf(TS::LOG, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d\n", cvErrorStr(status), delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
ts->printf(TS::LOG, "OpenCV Error:\n\t%d (%s%s) in %s, file %s, line %d\n", status, delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
return 0;
}
@ -638,7 +636,6 @@ void TS::update_context( BaseTest* test, int test_case_idx, bool update_ts_conte
current_test_info.test = test;
current_test_info.test_case_idx = test_case_idx;
current_test_info.code = 0;
cvSetErrStatus( cv::Error::StsOk );
}

@ -30,7 +30,7 @@ void TrackerMILModel::responseToConfidenceMap(const std::vector<Mat>& responses,
{
if (currentSample.empty())
{
CV_Error(-1, "The samples in Model estimation are empty");
CV_Error(cv::Error::StsError, "The samples in Model estimation are empty");
}
for (size_t i = 0; i < responses.size(); i++)

@ -70,7 +70,7 @@ bool TrackerModel::runStateEstimator()
{
if (!stateEstimator)
{
CV_Error(-1, "Tracker state estimator is not setted");
CV_Error(cv::Error::StsError, "Tracker state estimator is not setted");
}
Ptr<TrackerTargetState> targetState = stateEstimator->estimate(confidenceMaps);
if (!targetState)

Loading…
Cancel
Save