1

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:

In addition, it provides the method BORDER_TRANSPARENT . This means that the corresponding pixels in the destination image will not be modified at all. openCV manual

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

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

tir38
  • 9,810
  • 10
  • 64
  • 107

2 Answers2

3

... and the way to make the input image a four channel image is

cv::cvtColor(myImage, myImage, CV_BGR2BGRA);
Adrian
  • 551
  • 5
  • 16
0

warpPerspective sets the destination image to have the same type as the source. You need myImage to be CV_8UC4 too. That's why myWarpedImage has only three channels after the operation.

Sergio Basurco
  • 3,488
  • 2
  • 22
  • 40