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

**URL:** <https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395>\
**Category:** C++\
**Tags:** core, tapi, umat\
**Created:** [November 24, 2021, 9:04am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395 "2021-11-24T09:04:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhttp](https://avatars.discourse-cdn.com/v4/letter/z/a183cd/32.png) [@zhttp](https://forum.opencv.org/u/zhttp)\
**Post date:** [November 24, 2021, 9:04am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/1 "2021-11-24T09:04:35Z")

</div>

environment: window 10, c++, opencv 4.5.4(download from [this](https://opencv.org/releases/)), visual studio 2017,  
my minimal code:

```auto
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:

```auto
[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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 26, 2021, 11:02am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/2 "2021-11-26T11:02:00Z")

</div>

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

```auto
    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

> <https://github.com/opencv/opencv/blob/4.x/modules/imgproc/src/color.hpp#L106>

so dcn is 0 here:

> <https://github.com/opencv/opencv/blob/4.x/modules/imgproc/src/color.cpp#L141>

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

> <https://github.com/opencv/opencv/blob/4.x/modules/imgproc/src/color_lab.cpp#L4468>

please raise an issue on github !

---

<div class="post-metadata">

**Author:** ![zhttp](https://avatars.discourse-cdn.com/v4/letter/z/a183cd/32.png) [@zhttp](https://forum.opencv.org/u/zhttp)\
**Post date:** [November 29, 2021, 10:42am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/3 "2021-11-29T10:42:04Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 29, 2021, 10:56am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/4 "2021-11-29T10:56:50Z")

</div>

> [@zhttp](#):
>
> I switch “COLOR\_Lab2BGR” to “COLOR\_LUV2BGR” (because I just want light channel)

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

---

<div class="post-metadata">

**Author:** ![zhttp](https://avatars.discourse-cdn.com/v4/letter/z/a183cd/32.png) [@zhttp](https://forum.opencv.org/u/zhttp)\
**Post date:** [November 29, 2021, 11:06am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/5 "2021-11-29T11:06:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [November 29, 2021, 11:09am UTC](https://forum.opencv.org/t/unspecified-error-when-merge-vector-umat-into-umat-after-convert-color-space/6395/6 "2021-11-29T11:09:26Z")

</div>

> [@zhttp](#):
>
> I just switch and the problem is gone!

yep, right. mystery …
