Unspecified error when merge vector<umat> into umat, after convert color space

environment: window 10, c++, opencv 4.5.4(download from this), visual studio 2017,
my minimal code:

int main()
{
	cv::ocl::setUseOpenCL(true);
	cv::UMat img = cv::imread("my path to a jpg image").getUMat(cv::ACCESS_FAST);
	cv::UMat output;
	std::vector<cv::UMat> channels(img.channels());
	cv::cvtColor(img, img, cv::COLOR_BGR2Lab);
	cv::split(img, channels);
	cv::merge(channels, output);
	cv::cvtColor(output, output, cv::COLOR_Lab2BGR);

	return 0;
}

and the error message:

[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (1175) cv::ocl::haveOpenCL Initialize OpenCL runtime...
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (1181) cv::ocl::haveOpenCL OpenCL: found 1 platforms
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (973) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: initializing thread execution context
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (983) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: creating new execution context...
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (1001) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: device=Intel(R) HD Graphics 4000
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (399) cv::ocl::OpenCLBinaryCacheConfigurator::OpenCLBinaryCacheConfigurator Successfully initialized OpenCL cache directory: C:\Users\ADMINI~1\AppData\Local\Temp\opencv\4.5\opencl_cache\
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (423) cv::ocl::OpenCLBinaryCacheConfigurator::prepareCacheDirectoryForContext Preparing OpenCL cache configuration for context: Intel_R__Corporation--Intel_R__HD_Graphics_4000--10_18_10_4425
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\ocl.cpp (5353) cv::ocl::Context::Impl::__init_buffer_pools OpenCL: Initializing buffer pool for context@0 with max capacity: poolSize=134217728 poolSizeHostPtr=134217728
OpenCV(4.5.4) Error: Unspecified error (> Invalid number of channels in output image:
>     'VDcn::contains(dcn)'
> where
>     'dcn' is 0
) in __cdecl cv::OclHelper<struct cv::impl::`anonymous namespace'::Set<3,-1,-1>,struct cv::impl::A0x18431530::Set<3,4,-1>,struct cv::impl::A0x18431530::Set<0,5,-1>,2>::OclHelper(const class cv::debug_build_guard::_InputArray &,const class cv::debug_build_guard::_OutputArray &,int), file c:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc\src\color.hpp, line 229
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\parallel\registry_parallel.impl.hpp (96) cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load E:\opencv\opencv\build\x64\vc15\bin\opencv_core_parallel_onetbb454_64d.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb454_64d.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load E:\opencv\opencv\build\x64\vc15\bin\opencv_core_parallel_tbb454_64d.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb454_64d.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load E:\opencv\opencv\build\x64\vc15\bin\opencv_core_parallel_openmp454_64d.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp454_64d.dll => FAILED

! OPENCV warning: getUMat()/getMat() call chain possible problem.
!                 Base object is dead, while nested/derived object is still alive or processed.
!                 Please check lifetime of UMat/Mat objects!


let’s focus on this part:

OpenCV(4.5.4) Error: Unspecified error (> Invalid number of channels in output image:
>     'VDcn::contains(dcn)'
> where
>     'dcn' is 0
) in __cdecl cv::OclHelper<struct cv::impl::`anonymous namespace'::Set<3,-1,-1>,struct cv::impl::A0x18431530::Set<3,4,-1>,struct cv::impl::A0x18431530::Set<0,5,-1>,2>::OclHelper(const class cv::debug_build_guard::_InputArray &,const class cv::debug_build_guard::_OutputArray &,int), file c:\build\master_winpack-build-win64-vc15\opencv\modules\imgproc\src\color.hpp, line 229

it works fine with cv::Mat, but I get error like above when change to cv::UMat, please give me some suggestion, thanks!

1 Like

i think you found a bug.
it can be reproduced even without the split/merge:

    cv::ocl::setUseOpenCL(true);
	cv::Mat pic = cv::imread("img/1.png"); // keep base object alive !!
	cv::UMat img = pic.getUMat(cv::ACCESS_FAST);
	cv::UMat output;
	cv::cvtColor(img, output, cv::COLOR_Lab2BGR); //not Lab, but doesnt matter ..

there is no entry for Lab conversion here

so dcn is 0 here:

the forward conversion works, bc. it’s hardoded here:

please raise an issue on github !

@berak Thanks for your reply! in order to resolve my problem, I switch “COLOR_Lab2BGR” to “COLOR_LUV2BGR” (because I just want light channel), I will raise the issue when my project is completed(if the bug still here).

isnt it the same problem, dcn is 0 ? (same as hsv,hls, etc)

I’don’t know, I’m new in opencv, I just switch and the problem is gone!

yep, right. mystery …