Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

adding an alpha channel to a gpuMat?

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?

adding an alpha channel to a gpuMat?

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::imread("fore.bmp",1);
cv::Mat back = cv::imread("back.bmp" -1);
cv::imread("back.bmp",1);
cv::Mat alpha = cv::imread("matte.jpg",  0);


std::cout << fore.rows << " " << fore.cols << std::endl;
std::cout << back.rows << " " << back.cols << std::endl;
std::cout << alpha.rows << " " << alpha.cols << std::endl;

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::cvtColor(tmpBg, tmpBg, tmpAlphaImage.type());
cv::cuda::cvtColor(outPut, outPut, tmpAlphaImage.type());

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() (src.channels() == size) in <unnamed>::mergeImpl, 2) inanonymous-namespace'::BGR555_to_BGR, file D:/thirdParty/opencv_340/opencv-master/opencv-master/modules/cudaarithm/src/cuda/split_merge.cu, D:\thirdParty\opencv_340\opencv-master\opencv-master\modules\cudaimgproc\src\color.cpp, line 106315 `

What am i doing wrong here?

adding an alpha channel to a gpuMat?

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);


std::cout << fore.rows << " " << fore.cols << std::endl;
std::cout << back.rows << " " << back.cols << std::endl;
std::cout << alpha.rows << " " << alpha.cols << std::endl;

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::cvtColor(tmpBg, tmpBg, tmpAlphaImage.type());
cv::cuda::cvtColor(outPut, outPut, tmpAlphaImage.type());

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.channels() == 2) inanonymous-namespace'::BGR555_to_BGR, in `anonymous-namespace'::BGR555_to_BGR, file D:\thirdParty\opencv_340\opencv-master\opencv-master\modules\cudaimgproc\src\color.cpp, line 315
`

What am i doing wrong here?

adding an alpha channel to a gpuMat?

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);


std::cout << fore.rows << " " << fore.cols << std::endl;
std::cout << back.rows << " " << back.cols << std::endl;
std::cout << alpha.rows << " " << alpha.cols << std::endl;

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::cvtColor(tmpBg, tmpBg, tmpAlphaImage.type());
cv::cuda::cvtColor(outPut, outPut, tmpAlphaImage.type());

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.channels() == 2) in `anonymous-namespace'::BGR555_to_BGR, file D:\thirdParty\opencv_340\opencv-master\opencv-master\modules\cudaimgproc\src\color.cpp, line 315

What am i doing wrong here?