OpenCV Cuda alphaComp,反复混合0图像使其变暗

OpenCV Cuda alphaComp, blending a 0 image repeatedly makes it darker

我在使用 OpenCV 3.4.1 和 Cuda 进行 alpha 合成时遇到了奇怪的行为。

当我将一个全黑图像与一个全零 alpha 通道混合到另一个图像,并递归地重复这个过程时,图像变得更暗,亮度稳定在 50% 左右。

这是某种错误,还是我误解了有关 alpha 合成的一些基本知识?关于不同混合模式的文档很少。

我写了一个简短的示例代码来说明会发生什么。当 运行 一次时,矩形似乎保持绿色。但是,将其放入循环中会使矩形慢慢淡出,直到变成深绿色。

程序启动时的初始结果

几秒后的结果

#include <stdio.h>
#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudaarithm.hpp>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
    Mat frame(1080, 1920, CV_8UC4, Scalar(0, 0, 0, 255));

    namedWindow("test", CV_WINDOW_OPENGL);

    // Drawing a green rectangle with 100% opacity
    rectangle(frame, Rect(10, 10, 200, 200), Scalar(0, 255, 0, 255), CV_FILLED);

    cuda::GpuMat gpuFrame(frame);

    while(true){

        // Creating an all-black image with 0% opacity
        cuda::GpuMat gpuBlank(1080, 1920, CV_8UC4, Scalar(0, 0, 0, 0));

        // Alpha-compositing them together should keep the image untouched..?
        cuda::alphaComp(gpuFrame, gpuBlank, gpuFrame, cuda::ALPHA_OVER);

        // Splitting the image into 4 mats, to remove any resulting opacity from the image
        // Hopefully coming out with another 100% opacity image to blend again
        vector<cuda::GpuMat> frameChannels;
        cuda::split(gpuFrame, frameChannels);
        cuda::GpuMat fullAlpha(1080, 1920, CV_8UC1, Scalar(255));

        if (gpuFrame.channels() > 3) {
            frameChannels.pop_back();
        }
        frameChannels.push_back(fullAlpha);

        cuda::merge(frameChannels, gpuFrame);

        imshow("test", gpuFrame);
        waitKey(1);
    }
}

在对 CV_32FC4 图像进行更多测试后,这似乎是 OpenCV 处理与 CV_8UC4 图像的 alpha 合成方式中的一个错误。错误报告在这里:

https://github.com/opencv/opencv/issues/12212