本文介绍了创建具有透明边框的变形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个扭曲的图像,其中边框填充像素是透明的.我知道我可以使用BORDER_CONSTANT = BORDER_TRANSPARENT.但这是通过以下方式实现的:
I am trying to create a warped image where the border padding pixels are transparent. I know I can use the BORDER_CONSTANT = BORDER_TRANSPARENT. But this works by:
因此,要使边框像素透明,我是否需要从透明图像开始.像这个例子:
So to make border pixels transparent, do I need to start with a transparent image. Like this example:
int cols; // filled
int rows; // filled
Mat myImage; // filled
Mat warpMatrix (3, 4, CV_32FC1); // filled
Mat myWarpedImage;
myWarpedImage.create((cols, rows, CV_8UC4, Scalar(0,0,0,0)); // set all pixels to black, alpha = 0
warpPerspective(myImage, myWarpedImage, warpMatrix, Size(cols, rows), WARP_INVERSE_MAP, BORDER_TRANSPARENT);
这似乎不起作用.我变形的图像仍然是黑色背景且不透明(当我检查它时,使用了诸如GIMP之类的照片编辑软件).
This doesn't seem to work. My warped image still has black background with no transparency (when I check it some photo editing software like GIMP).
推荐答案
...,并使输入图像成为四通道图像的方法是
... and the way to make the input image a four channel image is
cv::cvtColor(myImage, myImage, CV_BGR2BGRA);
这篇关于创建具有透明边框的变形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!