Creating transparent overlay for camera in OpenCV c++
<p>I'm trying to create an overlay for a camera feed, and I want the overlay to be blurred, and about 50% transparent. One way of solving this is to copy each frame from the camera, draw onto it, and merge them together using addWeighted. This doesn't work for me because the blur effect takes up so much resources the output fps drops to 10.</p>

<p>Another solution I thought up is to create the overlay once (It's static after all, why recreate it every frame?) and merge it with the camera feed. However the resulting video gets noticeably darker when doing this, seemingly because the overlay mat refuses to be transparent.</p>

<pre><code>(*cap) &gt;&gt; frameOriginal;

orientationBackground = cv::Mat(frameOriginal.rows, frameOriginal.cols,
    frameOriginal.type(), cv::Scalar(0,0,0,0));
cv::Mat headingBackground;
orientationBackground.copyTo(headingBackground);

cv::Point layerpt1(1800, 675);
cv::Point layerpt2(1850, 395);
cv::rectangle(orientationBackground, layerpt1, layerpt2,
    cv::Scalar(255,80,80), CV_FILLED, CV_AA);

cv::blur(orientationBackground, orientationBackground, cv::Size(7,30));

double alpha = 0.5;
addWeighted(orientationBackground, alpha, frameOriginal, 1-alpha, 0, frameOriginal);
</code></pre>

<p>The before(left) and after(right) adding the overlay:<a href="https://i.stack.imgur.com/CHU1f.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CHU1f.jpg" alt="overlay problem"></a></p>

<p>I'm using OpenCV 3.10 on windows x64 btw</p>