From a0cff0be943309a941f93c50a7071179f9f12d5c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 8 Aug 2018 17:09:12 +0300 Subject: [PATCH] imgproc(cvtColor): slightly improve error messages Do not try to process empty inputs. --- modules/imgproc/src/color.cpp | 2 ++ modules/imgproc/src/color.hpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index 0ef29230cf..feec9bd19f 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -178,6 +178,8 @@ void cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) { CV_INSTRUMENT_REGION() + CV_Assert(!_src.empty()); + if(dcn <= 0) dcn = dstChannels(code); diff --git a/modules/imgproc/src/color.hpp b/modules/imgproc/src/color.hpp index 388a92c616..70e7844277 100644 --- a/modules/imgproc/src/color.hpp +++ b/modules/imgproc/src/color.hpp @@ -247,10 +247,14 @@ struct CvtHelper { CvtHelper(InputArray _src, OutputArray _dst, int dcn) { + CV_Assert(!_src.empty()); + int stype = _src.type(); scn = CV_MAT_CN(stype), depth = CV_MAT_DEPTH(stype); - CV_Assert( VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) ); + CV_Check(scn, VScn::contains(scn), "Invalid number of channels in input image"); + CV_Check(dcn, VDcn::contains(dcn), "Invalid number of channels in output image"); + CV_CheckDepth(depth, VDepth::contains(depth), "Unsupported depth of input image"); if (_src.getObj() == _dst.getObj()) // inplace processing (#6653) _src.copyTo(src);