I am using opencv merge function to merge 3 bands and got following error :
Exception thrown at 0x00007FFD6309441C in project2.exe: Microsoft C++ exception: osgeo::proj::io::FactoryException at memory location 0x00000075F16FC190.
Stackt trace is as follows
| |opencv_core460d.dll!icv_l9_owniCopy_8u_P3C3R()|Unknown|
| |opencv_core460d.dll!icv_l9_ippiCopy_8u_P3C3R()|Unknown|
| |opencv_core460d.dll!llwiCopyMerge(const void * const * pSrc, int srcStep, void * pDst, int dstStep, IppiSize size, int typeSize, int channels, int partial) Line 160|C|
| |opencv_core460d.dll!cv::ipp_merge(const cv::Mat * mv, cv::Mat & dst, int channels) Line 86|C++|
|>|opencv_core460d.dll!cv::merge(const cv::Mat * mv, unsigned __int64 n, const cv::debug_build_guard::_OutputArray & _dst) Line 144|C++|
| |opencv_core460d.dll!cv::merge(const cv::debug_build_guard::_InputArray & _mv, const cv::debug_build_guard::_OutputArray & _dst) Line 269|C++|
| |project2.exe!main() Line 137|C++|
Eception comes from this line executing :
case 3: return ippiCopy_8u_P3C3R((const Ipp8u**)pSrc, srcStep, (Ipp8u*)pDst, dstStep, size);
this Mat has only valid pixels, as long as the buffer object is valid.
(as soon as you leave the โforโ loop, those bands will point to invalid (temporary) memory !)
solution: you need to clone() those Matโs (so it allocates & copies actual pixels):