From dce310e03cabcc4e7ffdb490eb70e8be44f3d02d Mon Sep 17 00:00:00 2001 From: Sergei Nosov Date: Tue, 12 Jul 2016 18:03:28 +0300 Subject: [PATCH] provide better error messages --- modules/imgproc/include/opencv2/imgproc.hpp | 6 ++++-- modules/imgproc/src/emd.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 346c8e44f1..92bce5f780 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -3157,10 +3157,12 @@ same object. @param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix. Each row stores the point weight followed by the point coordinates. The matrix is allowed to have -a single column (weights only) if the user-defined cost matrix is used. +a single column (weights only) if the user-defined cost matrix is used. The weights must be +non-negative and have at least one non-zero value. @param signature2 Second signature of the same format as signature1 , though the number of rows may be different. The total weights may be different. In this case an extra "dummy" point is added -to either signature1 or signature2 . +to either signature1 or signature2. The weights must be non-negative and have at least one non-zero +value. @param distType Used metric. See cv::DistanceTypes. @param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix is used, lower boundary lowerBound cannot be calculated because it needs a metric function. diff --git a/modules/imgproc/src/emd.cpp b/modules/imgproc/src/emd.cpp index 22468da6d1..4dddbc6f14 100644 --- a/modules/imgproc/src/emd.cpp +++ b/modules/imgproc/src/emd.cpp @@ -387,7 +387,7 @@ static int icvInitEMD( const float* signature1, int size1, } else if( weight < 0 ) - CV_Error(CV_StsOutOfRange, ""); + CV_Error(CV_StsBadArg, "signature1 must not contain negative weights"); } for( i = 0; i < size2; i++ ) @@ -401,11 +401,13 @@ static int icvInitEMD( const float* signature1, int size1, state->idx2[dsize++] = i; } else if( weight < 0 ) - CV_Error(CV_StsOutOfRange, ""); + CV_Error(CV_StsBadArg, "signature2 must not contain negative weights"); } - if( ssize == 0 || dsize == 0 ) - CV_Error(CV_StsOutOfRange, ""); + if( ssize == 0 ) + CV_Error(CV_StsBadArg, "signature1 must contain at least one non-zero value"); + if( dsize == 0 ) + CV_Error(CV_StsBadArg, "signature2 must contain at least one non-zero value"); /* if supply different than the demand, add a zero-cost dummy cluster */ diff = s_sum - d_sum;