openCV: adding transparency to IplImage

后端 未结 2 545
北恋
北恋 2021-01-06 16:56

I have a 3-channel IplImage. I would like to create a 4-channel image and set the alpha channel for it to a value less than 1.0 to make it semi-transparent.

First I

2条回答
  •  日久生厌
    2021-01-06 17:27

    Maybe there is another way but I add transparency like this:

    // BGR split
    cvSplit(im1_bgr, im1_b, im1_g, im1_r, NULL);
    
    // Alpha channel creation (transparency)
    IplImage *im1_a = cvCreateImage(cvGetSize(im1_bgr), 8, 1);
    // Set the alpha value
    cvSet(im1_a, cvScalar(128), NULL);
    
    // Merge the 4 channel to an BGRA image
    IplImage *im1_bgra = cvCreateImage(cvGetSize(im1_bgr), 8, 4);
    cvMerge(im1_b, im1_g, im1_r, im1_a, im1_bgra);
    

提交回复
热议问题