I have three images, a foreground, a background and a mask. I need to add the mask as an alpha channel to the foreground, then use cv::cuda::alphaComp
to composite the results.
I am hitting some issues getting the alpha channel added, however. My code is:
cv::Mat fore = cv::imread("fore.bmp" -1);
cv::Mat back = cv::imread("back.bmp" -1);
cv::Mat alpha = cv::imread("matte.jpg", 0);
cv::Mat src1_rgba, src2_rgba, alphaImage;
cv::cuda::GpuMat tmpImage, tmpMask, tmpAlphaImage, tmpBg, outPut;
std::vector<cv::cuda::GpuMat> channels;
tmpImage.upload(fore);
tmpMask.upload(alpha);
tmpBg.upload(back);
cv::cuda::split(tmpImage, channels); // break image into channels
channels.push_back(tmpMask); // append alpha channel
cv::cuda::merge(channels, tmpAlphaImage); // combine channels
cv::cuda::alphaComp(tmpAlphaImage, tmpBg, outPut, cv::cuda::ALPHA_OVER);
outPut.download(alphaImage);
This compiles, but crashes with:
OpenCV(4.0.0-pre) Error: Assertion failed (src[i].size() == size) in <unnamed>::mergeImpl, file D:/thirdParty/opencv_340/opencv-master/opencv-master/modules/cudaarithm/src/cuda/split_merge.cu, line 106
What am i doing wrong here?